DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

reverse(3C++)


reverse -- reverse the order of elements in an array

Synopsis

   template <class T>
   void reverse(T* b,T* e);
   template <class T>
   void reverse_c(T* b1,T* e1,T* b2);

Assumptions

(1) For the copy version, the output array does not overlap the input array.

(2) For the copy version, the output array has at least as many cells as the input array.

(3) T has operator=.

Description

These functions reverse the elements of an array. That is, for every integer i between 0 and e-b-1, location e-(i+1) will have the same value after reversal that b + i had before reversal.

   template <class T>
   void reverse(T* b,T* e);

Reverses the array in place.

   template <class T>
   void reverse_c(T* b1,T* e1,T* b2);

Like reverse except that the input array is preserved and the result written to a new array beginning at location b2.

Complexity

If N is the size of the array, then complexity is O(N) for both versions. More precisely,

plain version

Exactly 3floor(N/2) assignments are done.

copy version

Exactly N assignments are done.

Notes

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(3C++), Block(3C++)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004