From 0ef0ca03797e471f33cedfd1793bcde525afce3a Mon Sep 17 00:00:00 2001 From: Pushkraj P Naik Date: Thu, 31 Oct 2024 17:36:20 +0530 Subject: [PATCH] menu driven code for creation of stack and it's operations --- october_2024/gfg_potd_31oct_2024_stack | Bin 0 -> 53576 bytes october_2024/gfg_potd_31oct_2024_stack.cpp | 96 +++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100755 october_2024/gfg_potd_31oct_2024_stack create mode 100644 october_2024/gfg_potd_31oct_2024_stack.cpp diff --git a/october_2024/gfg_potd_31oct_2024_stack b/october_2024/gfg_potd_31oct_2024_stack new file mode 100755 index 0000000000000000000000000000000000000000..cf8482dd437b1d57517bed7941686c20d1412981 GIT binary patch literal 53576 zcmeHwe|%KcweLPN0VaYPAu5#sL4phtF+U;ESO=3)0u<6DZJ|XE!(@P|lOJXVgo14} z_{8dcC6=dDeHxT{gBQKlQVX}X#YS7LTESYi6*c^@4c4~U(l$|J-goV@&dfe%W|9Hz z{o~!44?E|qbM{_)?e%M~{o`z2`ruC=j}bx>_&JcqB6Vg6adX=gdL%xBG!IGFYvx|% z{j#@qF+H{ZWMS*0IEe7Pj*Plq?_E-FeJ#s-tj`3)BkAd(ig5Ii9pCHa2EHe`kp!#wT#OGqls{cx<@f7>b^bt0 zM34AZ*zs+>)WFxp_y|_*wl~ix<@y()Ad030&pRc6H(*C1OJs68P4v zh!t>Rd@am3!b|1N-$>j{GXY$QE<!XAyX8846gxCVc5O2mK72GC753X%@!+uZ*YA0%t==T_>GjRP0()mcqeg)qV zqAtNpDw~T$dUo-eaO=gP;EIbI)`uDZ({BP2(ec;H&-A@`e%VKNzVW4-F8Jltx*|Nw zMKaoSChpFZ_mcmkzLIevp2+s$N*(pjeF7gxcIt@-QLha-W;Syylo!YVF6B6?PTQ;27Aoxw2imwpqG=zZ=>pj8q= zPt(6N2hto!b0E!uGzU(d1B2a;0|OgQ+d0tg==f>(zk{! z)jl>_Y(-z1P48}WwAJoX;HR8zwOtJ7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fUpeT ztjq5}tr2JPiL{f@^&zUI$qX8m4R1EXx7;$O4X?(R-YOpq1>~h=tH&CGzEfE#O0Zfo zEc#cy8@ztbTk5g5wdXv(+gJH=Z0zpOrE>WGD1}ZW4tgQ^rT`I(>?d1x3U_ z;lOokY+=DEZ6v6nv8L*D?BDy(Hck>y2(wKh$L*dVZ)-m^z{}sv``4~eFj+e@G?9)l zz^DXEOK5E@W0LRwjfqe`8vrX%u@f82jS{qn1MNc?hJWOCqPuRqc&s@7!tz9D5_8n5 zanxG-&XCx87h7YrTAVrHTcs@2vZ8Uea^tiE91D@8#U(3)mXWf-KrVeUZJ52%7Yrqx zQXH0!GJJv_ra7^gjQGp)xCUPzY>2E@vRPzaYBU(#EKYZT1d}woGz@i6*2m~TjF2k5 zQ`!J$kt3g7VY2d+5SAcp_a$j+Oatr;`4k$W`W)*a90~egQrJ^!9>ylEffg?fpH7gi60#6*j5?!CPj8BO0 zVXCm8u@tu0D7v^|cMH)eFv&3_n@3%MVl|j4;Fa)CWP3D!gAF@6FLcFO;U_|lKo=`A zq2{JlpDtdK5D`t7|234;>@(F6UftX}Jahg)3~5v*j~7_wE=ymLZ2lZi1j#$v+5zzc9|e)E@&XZRk>F;+P6v7JMHE7*$nOOWV?FCSmZ&2@+|1~}Z`S@ek&{j^mp z$-PDz^y0#1%s3SlU_6EJ)qkz{!DC0f6LLR%?L(Gg8E%q|9s}D53jlJ&?|?Reth)5zEi&Q3Gcvrj~_nve062v;k?tU^Y^cKpwRpM zN4~M^@g>baKelpT#%l)-T-A?}x^w!8 zJ9Ag<+Yef_%|d-pYVeCu2P@!9ep_IRDUoB#a%zkc`sE?v_7?i+QF zj@G(geb{&NFaG-CXMUCY{N3N)HuDdg{~5XQrI}Cut>X cd(T}x +#include + +class Stack { +private: + std::vector data; + +public: + void push(int value) { + data.push_back(value); + } + + void pop() { + if (!data.empty()) { + data.pop_back(); + } else { + std::cout << "Stack is empty!" << std::endl; + } + } + + int top() const { + if (!data.empty()) { + return data.back(); + } + std::cerr << "Stack is empty!" << std::endl; + return -1; // or any error code + } + + bool isEmpty() const { + return data.empty(); + } + + int size() const { + return data.size(); + } + + void display() const { + if (data.empty()) { + std::cout << "Stack is empty!" << std::endl; + return; + } + std::cout << "Stack elements: "; + for (int i = data.size() - 1; i >= 0; i--) { + std::cout << data[i] << " "; + } + std::cout << std::endl; + } +}; + +int main() { + Stack stack; + int choice, value; + + do { + std::cout << "\nMenu:\n"; + std::cout << "1. Push\n"; + std::cout << "2. Pop\n"; + std::cout << "3. Top\n"; + std::cout << "4. Check if Empty\n"; + std::cout << "5. Get Size\n"; + std::cout << "6. Display Stack\n"; + std::cout << "7. Exit\n"; + std::cout << "Enter your choice: "; + std::cin >> choice; + + switch (choice) { + case 1: + std::cout << "Enter value to push: "; + std::cin >> value; + stack.push(value); + break; + case 2: + stack.pop(); + break; + case 3: + std::cout << "Top element: " << stack.top() << std::endl; + break; + case 4: + std::cout << (stack.isEmpty() ? "Stack is empty." : "Stack is not empty.") << std::endl; + break; + case 5: + std::cout << "Stack size: " << stack.size() << std::endl; + break; + case 6: + stack.display(); + break; + case 7: + std::cout << "Exiting..." << std::endl; + break; + default: + std::cout << "Invalid choice. Please try again." << std::endl; + } + } while (choice != 7); + + return 0; +}