#include #include #include #include #include #include using namespace std; int main(int narg, char **arg){ vector v; srand(time(0)); for(int i = 0; i < 5; i++){ cout << " v.size() " << v.size() << " v.capacity() " << v.capacity() << endl; v.push_back(rand()%20); } // iterator approach cout << "iterator access " << endl; vector::iterator it; for(it = v.begin(); it != v.end(); it++) cout << *it << endl; // show algorithm sort(v.begin(),v.end()); ostream_iterator out(cout, " "); copy(v.begin(), v.end(), out); vector z(3);// should be 5 // index approach cout << "index access " << endl; for(i = 0; i < 5; i++){ //z[i] = v[i]; // goes out of bounds z.push_back(v[i]); // mixing bad cout << z[i] << endl; } // Linked List example. cout << "Linked List example " << endl; list larry; for(int i = 0; i < 5; i++) larry.push_back(static_cast(rand()%20)); list::iterator il; for(il = larry.begin(); il != larry.end(); il++) cout << *il << endl; return EXIT_SUCCESS; }