I can sort a vector with the following code. However, if I change vector to list it doesn't work. Doesn't sort() work with all STL containers?
Code:#include <vector> #include <list> #include <iostream> #include <algorithm> #include <ctime> using namespace std; int main() { srand(time(0)); vector<int> v; for (int i = 0; i < 10; i++) v.push_back(rand()); sort(v.begin(), v.end()); vector<int>::iterator it = v.begin(); while (it != v.end()) { cout << *it << ' '; it++; } cin.get(); }