Tue Dec 10 2019
STL Sort
C++ Programming1193 views
File Name: stl-sort.cpp
/* STL Sorting with vector */
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
int array[] = {3,5,7,9,8,0,1,6,2,4};
int size = (sizeof((array))/sizeof((*array)));
/* Create vector as the length of array */
vector<int> list(array,array+size);
/* Create an vector iterator */
vector<int>::iterator data;
/* Sort data using default comparison */
sort(list.begin(),list.end());
cout << "After sorting:" << endl;
/* Display data from vector */
for(data = list.begin(); data != list.end(); data++)
cout << *data << endl;
return 0;
}
/* Output */
After sorting:
0
1
2
3
4
5
6
7
8
9
Reference:
Sequence container in C++
Author:Geekboots