Sort a subset of the container : sort « STL Algorithms Sorting « 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++ » STL Algorithms Sorting » sortScreenshots 
Sort a subset of the container
  
#include <cstdlib>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

void show(const char *msg, vector<int> vect);

int main()
{
  vector<int> v(10);
  for(unsigned i=0; i < v.size(); i++)
    v[i= rand() 100;

  show("Original order:", v);

  sort(v.begin()+2, v.end()-2);

  show("sorting elements v[2] to v[7] into natural order:", v);

  return 0;
}

void show(const char *msg, vector<int> vect) {
  cout << msg << endl;
  for(unsigned i=0; i < vect.size(); ++i)
    cout << vect[i<< endl;
  
}
  
    
  
Related examples in the same category
1.Using an in-place generic sort algorithm
2.Sort a vector and print out the sorted elements
3.Sort all element in an array
4.Sort part of the elements in an array
5.Sort a vector into ascending order of id members
6.Sort elements in deque
7.Sort elements reversely with custom function
8.Using the generic sort algorithm with a binary predicate: greater
9.Use custom function and sort to sort strings by length
10.Sorting user-defined class
11.Sort the entire container
12.Sort into descending order by using greater
13.Sort random number
14.Sort a string array with sort()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.