#include #include #include using namespace std; int main() { const int NUMELS = 5; int a[NUMELS] = {1,2,3,4,5}; char b[NUMELS] = {'a','b','c','d','e'}; int i; // instantiate an integer and character vector // using a constructor to set the size of each vector // and initialize each vector with values vector x(a, a + NUMELS); vector y(b, b + NUMELS); cout << "\nThe vector x initially contains the elements: " << endl; for (i = 0; i < NUMELS; i++) cout << x[i] << " "; cout << "\nThe vector y initially contains the elements: " << endl; for (i = 0; i < NUMELS; i++) cout << y[i] << " "; // instantiate two ostream objects ostream_iterator outint(cout, " "); ostream_iterator outchar(cout, " "); // modify elements in the existing list x.at(3) = 6; //set element at position 3 to a 6 y.at(3) = 'f'; // set element at position 3 to an 'e' // add elements to the end of the list x.insert(x.begin() + 2,7); // insert a 7 at position 2 y.insert(y.begin() + 2,'g'); // insert an f at position 2 cout << "\n\nThe vector x now contains the elements: " << endl; copy(x.begin(), x.end(), outint); cout << "\nThe vector y now contains the elements: " << endl; copy(y.begin(), y.end(), outchar); //sort both vectors sort(x.begin(), x.end()); sort(y.begin(), y.end()); cout << "\n\nAfter sorting, vector x's elements are: " << endl; copy(x.begin(), x.end(), outint); cout << "\nAfter sorting, vector y's elements are:" << endl; copy(y.begin(), y.end(), outchar); // random shuffle the existing elements random_shuffle(x.begin(), x.end()); random_shuffle(y.begin(), y.end()); cout << "\n\nAfter random shuffling, vector x's elements are:" << endl; copy(x.begin(), x.end(), outint); cout << "\nAfter random shuffling, vector y's elements are:" << endl; copy(y.begin(), y.end(), outchar); cout << endl; return 0; }