#include #include #include #include #include #include using namespace std; stack st; // push three elements into the stack st.push(1); st.push(2); st.push(3); st // pop and print two elements from the stack cout << st.top() << ' '; st.pop(); cout << st.top() << ' '; st.pop(); // modify top element st.top() = 77; // push two new elements st.push(4); st.push(5); // pop one element without processing it st.pop(); // pop and print remaining elements while (!st.empty()) { cout << st.top() << ' '; st.pop(); } cout << endl; queue q; // insert three elements into the queue q.push("Bob"); q.push("Sue"); q.push("Tim"); // read and print two elements from the queue cout << q.front() << " "; q.pop(); cout << q.front() << " "; q.pop(); // insert two new elements q.push("Jasper"); q.push("Homer"); // skip one element q.pop(); // alien abduction // read and print two elements cout << q.front() << " "; q.pop(); cout << q.front() << endl; q.pop(); q.push("Zoey"); // print number of elements in the queue cout << "Number of people waiting in line: " << q.size() << endl; vector v{1,2,3,4}; vector w(4); copy(v.rbegin(), v.rend(), w.begin()); w for (auto it = v.rbegin(); it != v.rend(); ++it) { cout << *it << " "; } cout << endl; vector v, w; for(int i = 3; i <= 5; i++) { v.push_back(i); w.push_back(i * 10); } v w v.size() copy(w.begin(), w.end(), v.begin()); v copy(w.begin(), w.end(), back_inserter(v)); v deque v, w; for(int i = 3; i <= 5; i++) { v.push_back(i); w.push_back(i * 10); } v copy(w.begin(), w.end(), front_inserter(v)); v vector v, w; for(int i = 3; i <= 5; i++) { v.push_back(i); w.push_back(i * 10); } v copy(w.begin(), w.end(), inserter(v, v.begin() + 1)); v vector v; copy(istream_iterator (cin), istream_iterator (), // works like end back_inserter(v)); v vector v{0,1,2,3,4}; ostream_iterator outIter(cout, " "); copy(v.begin(), v.end(), outIter); std::string paragraph = R"""( It was the best of times it was the worst of times it was the age of wisdom it was the age of foolishness it was the epoch of belief it was the epoch of incredulity it was the season of Light it was the season of Darkness it was the spring of hope it was the winter of despair we had everything before us we had nothing before us we were all going direct to Heaven we were all going direct the other way in short the period was so far like the present period that some of its noisiest authorities insisted on its being received for good or for evil in the superlative degree of comparison only )"""; std::stringstream stream(paragraph); // count the number of times each word occurs in the input std::map word_count; // empty map from string to size_t std::string word; while (stream >> word) { ++word_count[word]; } for (const auto &w : word_count) cout << w.first << " occurs " << w.second << " times" << endl;