STL algorithms

I know that the STL includes algorithms for sorting containers as well as the ADTs for the containers themselves, but can anyone explain in detail in detail (not really code, just so that I understand it conceptually) how you would go about using a sorting algorithm on some container?

Thanks
This should help:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main(){
  std::vector<int> MyVector;
  
  for (int i = 0; i < 10; i++)
	  MyVector.push_back(rand());

  std::sort(MyVector.begin(), MyVector.end());

  vector<int>::iterator it;
  for (it = MyVector.begin(); it < MyVector.end(); ++it)
	  std::cout << *it << ',';

  return 0;
}









MyVector now has 10 random values

MyVector now has 10 random values in order (lowest-to-highest)



41,6334,11478,15724,18468,19169,24464,26500,26962,29358
Last edited on
Check it out my blog http://www.surprising-code.com/p/pointers-to-member-functions.html

Maybe it helps if not feel free to ask again and I try to answer.
I don't understand your question.
You want to know how to sort (sorting algorithms) or how to do sort( container )
Because "that's it" for the latter case.
Topic archived. No new replies allowed.