Can anyone explain stack in simple way? Specially about push(), pop(), and peak()... With some example...

Question from data structure... You can use any programming language for giving example

11/16/2019 4:20:15 AM

Prince Raj

9 Answers

New Answer


Consider stack as a pile of books... Constraints are u can put book on top and remove from top.... 1.push means adding book on top. 2.pop means removing book from top 3.peek means to get value ie name of top book


Technical term for stack operation is LIFO ie last in first out data structure


Give it a try... If u have any doubt then ask... How can u ask for complete code.. Only 3-4 functions u need to write and a stack class or structure


Code can be found anywhere on internet.... For array as well as linked list implementation I told u the concept...


Stack is the linear data Structure it is in the form of LIFO means last in first out example of real life is Undo/Redo stacks in Excel or Word...


Prince Raj Maybe this will help, https://code.sololearn.com/curEw257NKt9/?ref=app


A stack is like a stack of plates. You can only add (push) and remove (pop) plates from the top. It uses the LIFO principle. That is, Last in first out.


Saurabh B can you explain with some code how can we use?


Saurabh B yes there is but I want simple code which is easy to understand how can we use stack, those are complicated?