Right-rotate a sequence in vector : Vector Utility « Data Structure « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » Data Structure » Vector UtilityScreenshots 
Right-rotate a sequence in vector
Right-rotate a sequence in vector


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  vector<int> vectorObject;
  vector<int>::iterator p;
  int i;
  
  for(i = 0; i <10; i++
     vectorObject.push_back(i);

  cout << "Original ordering: ";
  for(p=vectorObject.begin(); p<vectorObject.end(); p++)
    cout << *p << " ";
  cout << endl;

  // rotate right two positions using reverse iterators
  rotate(vectorObject.rbegin(), vectorObject.rbegin()+2, vectorObject.rend());

  cout << "Order after two right rotates: ";
  for(p=vectorObject.begin(); p<vectorObject.end(); p++)
    cout << *p << " ";
  cout << endl;

  return 0;
}


           
       
Related examples in the same category
1.Demonstrate inner_product() in vectorDemonstrate inner_product() in vector
2.Demonstrate partial_sum() in vectorDemonstrate partial_sum() in vector
3.set_union, set_difference, set_symmetric_difference, set_intersection
4.Use a unary function object to determine even/odd.Use a unary function object to determine even/odd.
5.Demonstrate count_if and not1 in vectorDemonstrate count_if and not1 in vector
6.Another way to sort a sequence into descending order.Another way to sort a sequence into descending order.
7.Use a function adaptor in vectorUse a function adaptor in vector
8.Demonstrate insert_iterator in a vectorDemonstrate insert_iterator in a vector
9.Insert one vector into another using an insert iteratorInsert one vector into another using an insert iterator
10.Demonstrate back_insert_iterator in vectorDemonstrate back_insert_iterator in vector
11.Demonstrate front_insert_iterator in vectorDemonstrate front_insert_iterator in vector
12.Find minimum and maximum inside a vectorFind minimum and maximum inside a vector
13.Use for_each() in vectorUse for_each() in vector
14.Use the logical_not unary function object in vectorUse the logical_not unary function object in vector
15.Sorting a vector into descending order in vectorSorting a vector into descending order in vector
16.Using copy() in VectorUsing copy() in Vector
17.Using swap_ranges() in VectorUsing swap_ranges() in Vector
18.Exchange elements from two different types of containers.Exchange elements from two different types of containers.
19.Demonstrate find() and find_if() in vectorDemonstrate find() and find_if() in vector
20.Demonstrate search() in vectorDemonstrate search() in vector
21.Demonstrate mismatch() in vectorDemonstrate mismatch() in vector
22.Demonstrating sort() in vectorDemonstrating sort() in vector
23.Demonstrating partial_sort() in vectorDemonstrating partial_sort() in vector
24.Demonstrate binary_search() in vectorDemonstrate binary_search() in vector
25.Demonstrate lower_bound() in vectorDemonstrate lower_bound() in vector
26.Demonstrating remove() and replace() in vectorDemonstrating remove() and replace() in vector
27.Demonstrating unique() in vectorDemonstrating unique() in vector
28.Transforming a sequence in vectorTransforming a sequence in vector
29.Generating a sequence in vectorGenerating a sequence in vector
30.Rotate a sequence in vectorRotate a sequence in vector
31.Demonstrate random_shuffle() in vectorDemonstrate random_shuffle() in vector
32.Merge two sequences Merge two sequences
33.A vector may allocate more memory than it currently needs. A vector may allocate more memory than it currently needs.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.