+5

# 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

+7

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

+5

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

+5

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

+4

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

+4

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...

+2

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

+1

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.

0

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

0

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