STL Sort

/* 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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!