Created
December 26, 2019 13:34
-
-
Save Lucas-Severo/eae3564358fcefa828f85b0e3e165b27 to your computer and use it in GitHub Desktop.
Revisions
-
Lucas-Severo created this gist
Dec 26, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ #include <iostream> #include <stack> using namespace std; void showBooks(stack<string> books) { if(!books.empty()) { cout << "\n\tBooks in the stack:" << endl; while(!books.empty()) { cout << "\t" << books.top() << endl; books.pop(); } } else { cout << "\n\tEmpty stack" << endl; } } int main() { stack<string> books; int opt; string name; do { cout << "\nWhat do you want to do?" << endl; cout << "1 - Add new book" << endl; cout << "2 - Remove a book from the stack" << endl; cout << "3 - Show stack size" << endl; cout << "4 - Show stack" << endl; cout << "5 - Exit" << endl; cout << ">>> "; cin >> opt; switch(opt) { case 1: cin.get(); cout << "\nName: "; getline(cin, name); books.push(name); break; case 2: if(!books.empty()) { cout << "\n\tBook Removed: " << books.top() << endl; books.pop(); } break; case 3: cout << "\n\tSize: " << books.size() << endl; break; case 4: showBooks(books); break; case 5: break; default: cout << "\n\tUnknown option" << endl; break; } } while(opt != 5); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #include <iostream> #include <stack> using namespace std; int main() { stack<int> st; st.push(10); st.push(20); st.push(30); st.push(40); st.push(50); int stackSize = st.size(); cout << "Size: " << stackSize << endl; while(!st.empty()){ cout << st.top() << endl; st.pop(); } return 0; }