How to partial sort a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<int> vec{ 3, 6, 9, 8, 4, 7, 2, 5, 1, 0 };

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

	for (int val : vec)
		cout << val << " ";

	cout << endl;

	return 0;
}

/*
run:

0 1 2 3 4 9 8 7 6 5

*/

 



answered Apr 30, 2018 by avibootz
...