/* Author: Arun Somasundaram, CSE Dept, OSU Simple Program with Standard Template Library Examples of Containers(Vectors) / Iterators / Algorithms */ #include #include #include using namespace std; int main(){ //---------- Vector / Iterators / Sort & Reverse ------------// vector iVec; iVec.push_back(100); //push to the end of the vector iVec.push_back(101); //push to the end of the vector cout << "Front item " << iVec.front() << endl; cout << "Back item " << iVec.back() << endl; cout << "is iVec Empty " << iVec.empty() << endl; cout << "iVec's size " << iVec.size() << endl << endl; iVec.pop_back(); //pop the back item of the vector cout << "After pop" << endl; cout << "Front item " << iVec.front() << endl; cout << "Back item " << iVec.back() << endl << endl; iVec.push_back(101); cout << "Item at index 1 after push is " << iVec.at(1) << endl << endl; vector iVecCopy; //Assign a copy iVecCopy = iVec; cout << "After Copy" << endl; cout << "Front item " << iVecCopy.front() << endl; cout << "Back item " << iVecCopy.back() << endl << endl; iVec.push_back(102); cout << "After pushing 102" << endl; vector::iterator iIterator = iVec.begin(); for( iIterator = iVec.begin(); iIterator != iVec.end(); iIterator++ ){ cout << *iIterator << " "; } cout << endl << endl; iIterator = iVec.begin(); iIterator++; iVec.insert(iIterator, 103); cout << "After inserting 103" << endl; for( iIterator = iVec.begin(); iIterator != iVec.end(); iIterator++ ){ cout << *iIterator << " "; } cout << endl << endl; sort(iVec.begin(), iVec.end()); cout << "After Sorting" << endl; for( iIterator = iVec.begin(); iIterator != iVec.end(); iIterator++ ){ cout << *iIterator << " "; } cout << endl << endl; reverse(iVec.begin(), iVec.end()); cout << "After Reversing" << endl; for( iIterator = iVec.begin(); iIterator != iVec.end(); iIterator++ ){ cout << *iIterator << " "; } cout << endl << endl; return 0; }