// #include "stdafx.h" #include #include #include #include #include #include #include using namespace std; // begin(): Returns a random-access iterator to the first element in the container. // end(): Returns a random-access iterator that point just beyond the end of the vector. // rbegin() Returns an iterator to the first element in a reversed vector. // rend() Returns an iterator to the end of a reversed vector. // back(): Returns a reference to the last element of the vector. // front() Returns a reference to the first element in a vector. // pop_back() Deletes the element at the end of the vector. // push_back() Add an element to the end of the vector. // clear(): Erases the elements of the vector. // empty(): Tests if the vector container is empty. // erase() Removes an element or a range of elements in a vector from specified positions. // insert() Inserts an element or a number of elements into the vector at a specified position. // size() Returns the number of elements in the vector. // max_size() Returns the maximum length of the vector. // resize() Specifies a new size for a vector. // capacity(): Returns the number of elements that the vector could contain without allocating more storage. // reserve() Reserves a minimum length of storage for a vector object. // assign(): Erases a vector and copies the specified elements to the empty vector. // at(): Returns a reference to the element at a specified location in the vector. int main() { // Vectors vector hw; double *y; double x; while(cin >> x) {//Reads values till ctrl d hw.push_back(x); } cout << "Elements read in were: " << endl; for(int i=0; i::size_type size = hw.size(); if(size == 0) { cout << "The size must not be Zero" << endl; return 1; } cout << "The number of elements is: " << size << endl; cout << endl; sort(hw.begin(), hw.end()); cout << "Sorted list: " << endl; for(int i=0; i::size_type mid = size / 2; double median = (size % 2 == 0) ? (hw[mid] + hw[mid+1]) / 2 : hw[mid]; cout << "The median is " << median << endl; random_shuffle(hw.begin(), hw.end()); cout << "Random Shuffled list: " << endl; for(int i=0; i::iterator itr; for ( itr = hw.begin(); itr != hw.end(); ++itr ) cout << *itr << endl; cout << endl; }