# Demonstrating partial_sort() in vector : Vector Utility « Data Structure « C++

Demonstrating partial_sort() in vector

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

void init_vectorObject(vector<int> &vectorObject)
{
vectorObject[0] = 1;
vectorObject[1] = 10;
vectorObject[2] = 2;
vectorObject[3] = -3;
vectorObject[4] = 9;
vectorObject[5] = 4;
vectorObject[6] = 8;
vectorObject[7] = 5;
vectorObject[8] = 7;
vectorObject[9] = 6;
}

int main()
{
vector<int> vectorObject(10);
int i;

init_vectorObject(vectorObject);

cout << "Original order:";
for(i = 0; i <10; i++)
cout << vectorObject[ i ] << " ";
cout << endl;

partial_sort(vectorObject.begin(), vectorObject.begin()+5, vectorObject.end());

cout << "Order after partial sorting:";
for(i = 0; i <10; i++)
cout << vectorObject[ i ] << " ";
cout << endl;

return 0;
}

```

### Related examples in the same category

 1 Demonstrate inner_product() in vector 2 Demonstrate partial_sum() in vector 3 set_union, set_difference, set_symmetric_difference, set_intersection 4 Use a unary function object to determine even/odd. 5 Demonstrate count_if and not1 in vector 6 Another way to sort a sequence into descending order. 7 Use a function adaptor in vector 8 Demonstrate insert_iterator in a vector 9 Insert one vector into another using an insert iterator 10 Demonstrate back_insert_iterator in vector 11 Demonstrate front_insert_iterator in vector 12 Find minimum and maximum inside a vector 13 Use for_each() in vector 14 Use the logical_not unary function object in vector 15 Sorting a vector into descending order in vector 16 Using copy() in Vector 17 Using swap_ranges() in Vector 18 Exchange elements from two different types of containers. 19 Demonstrate find() and find_if() in vector 20 Demonstrate search() in vector 21 Demonstrate mismatch() in vector 22 Demonstrating sort() in vector 23 Demonstrate binary_search() in vector 24 Demonstrate lower_bound() in vector 25 Demonstrating remove() and replace() in vector 26 Demonstrating unique() in vector 27 Transforming a sequence in vector 28 Generating a sequence in vector 29 Rotate a sequence in vector 30 Right-rotate a sequence in vector 31 Demonstrate random_shuffle() in vector 32 Merge two sequences 33 A vector may allocate more memory than it currently needs.