C++ Programming

STL Sort

C plus plus example for sorting using standard template library

12/10/2019
0 views
stl-sort.cppCPP
/* 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
cppc plus plusSTL sortingstandard template library

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com