The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Интерактивная система просмотра системных руководств (man-ов)

 ТемаНаборКатегория 
 
 [Cписок руководств | Печать]

reverse (3)
  • >> reverse (3) ( Solaris man: Библиотечные вызовы )
  • Ключ reverse обнаружен в базе ключевых слов.
  • 
                           Standard C++ Library
                 Copyright 1998, Rogue Wave Software, Inc.
    
    
    NAME
         reverse
    
          - Reverses the order of elements in a collection.
    
    
    
    SYNOPSIS
         #include <algorithm>
         template <class BidirectionalIterator>
         void reverse (BidirectionalIterator first,
                      BidirectionalIterator last);
    
    
    
    DESCRIPTION
         The algorithm reverse reverses the elements in a sequence so
         that the last element becomes the new first element, and the
         first element becomes the new last.  For  each  non-negative
         integer  i  <= (last - first)/2, reverse applies swap to all
         pairs of iterators first + I, (last - I) - 1.
    
         Because the  iterators  are  assumed  to  be  bidirectional,
         reverse does not return anything.
    
    
    
    COMPLEXITY
         reverse performs exactly (last - first)/2 swaps.
    
    
    
    EXAMPLE
         //
         // reverse.cpp
         //
          #include <algorithm>
          #include <vector>
          #include <iostream>
         using namespace std;
         int main()
          {
            //Initialize a vector with an array of ints
           int arr[10] = {1,2,3,4,5,6,7,8,9,10};
           vector<int> v(arr, arr+10);
    
            //Print out elements in original (sorted) order
           cout << "Elements before reverse: " << endl << "     ";
           copy(v.begin(),v.end(),
                ostream_iterator<int,char>(cout," "));
           cout << endl << endl;
    
            //Reverse the ordering
            reverse(v.begin(), v.end());
    
            //Print out the reversed elements
           cout << "Elements after reverse: " << endl << "     ";
    
           copy(v.begin(),v.end(),
                ostream_iterator<int,char>(cout," "));
           cout << endl;
    
           return 0;
          }
    
         Program Output
    
    
    
         Elements before reverse:
             1 2 3 4 5 6 7 8 9 10
         Elements after reverse:
             10 9 8 7 6 5 4 3 2 1
         A reverse_copy to cout:
             1 2 3 4 5 6 7 8 9 10
    
    
    
    WARNINGS
         If your compiler does not support default  template  parame-
         ters,  then you always need to supply the Allocator template
         argument. For instance, you need to write:
    
         vector<int, allocator<int> >
    
         instead of:
    
         vector<int>
    
         If your compiler does not support namespaces,  then  you  do
         not need the using declaration for std.
    
    
    
    SEE ALSO
         reverse_copy, swap
    
    
    
    


    Поиск по тексту MAN-ов: 




    Партнёры:
    PostgresPro
    Inferno Solutions
    Hosting by Hoster.ru
    Хостинг:

    Закладки на сайте
    Проследить за страницей
    Created 1996-2024 by Maxim Chirkov
    Добавить, Поддержать, Вебмастеру