+ 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

16th Nov 2019, 4:20 AM
Prince Raj
Prince Raj - avatar
9 Antworten
+ 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
16th Nov 2019, 4:23 AM
Saurabh B
Saurabh B - avatar
+ 5
Technical term for stack operation is LIFO ie last in first out data structure
16th Nov 2019, 4:24 AM
Saurabh B
Saurabh B - avatar
+ 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
16th Nov 2019, 4:41 AM
Saurabh B
Saurabh B - avatar
+ 4
Code can be found anywhere on internet.... For array as well as linked list implementation I told u the concept...
16th Nov 2019, 4:26 AM
Saurabh B
Saurabh B - avatar
16th Nov 2019, 5:34 PM
Akash
Akash - avatar
+ 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.
16th Nov 2019, 7:01 PM
Logomonic Learning
Logomonic Learning - avatar
0
Saurabh B can you explain with some code how can we use?
16th Nov 2019, 4:25 AM
Prince Raj
Prince Raj - avatar
0
Saurabh B yes there is but I want simple code which is easy to understand how can we use stack, those are complicated?
16th Nov 2019, 4:29 AM
Prince Raj
Prince Raj - avatar