+ 6
Can anyone please tell the purpose of stack(data structure) in python?
Like it's used to solve expressions ?
19 odpowiedzi
+ 7
Shabnam Shaikh ok sister I'll do !
+ 5
Stack (data structure) follows the LIFO(Last In First Out) principle.
Real time example: the Undo option(shortcut ctrl+Z), it is used to remove(or goes back or erase) the recently(last) done work.
Hope it helps, Thanks for reading my response.
+ 4
But the main purpose not clarifies!
+ 4
Exactly, like anything else in programming, if you really know what you're doing then you can make things do what you want. Please, don't even worry about stacks until you are comfortable with a language and know basic data types
+ 4
Mohd Aadil
It's used in solving any kind of expression like prefix , infix and postfix expressions?
+ 4
Oh okay tysm Durga Devi
+ 4
Add some durability to the language
+ 3
The internet is your friend
https://www.thoughtco.com/definition-of-stack-in-programming-958162
+ 3
Hey Yusra Stack is a data structure, works on first in last out.
Suppose you have square 🔲 pieces and you keep them one above another ( like building ) this will become a stack, now if you wish to remove then you will remove from top of collection.
It's stack principle
+ 3
Durga Devi can you explain last line ?
that's what I m asking
+ 3
Yusra
Python's built-in list type makes a decent stack data structure as it supports push and pop operations in amortized O(1) time. Python's lists are implemented as dynamic arrays internally which means they occasional need to resize the storage space for elements stored in them when elements are added or removed.
https://dbader.org/blog/stacks-in-python#:~:text=Python's%20built%2Din%20list%20type,elements%20are%20added%20or%20removed.
+ 3
-Stack is a linear data structure.
-Insertion and deletion take place at one end called top.
-Works on LIFO mechanism (Last in First out) which means elements inserted in last is first to remove from stack.
-Push and pop are basic operation that is used for insertion and deletion of element.
-eg.- Dine of plates, stack of books and so on.
+ 2
Yusra I was saying what actually is stack, but it looks like you were looking for stack applications 😊
+ 2
Actually stack is having different architectures in different programming environments like FIFO, LIFO etc. Usually two types of implementations are used - data is stored OR address of the data is stored.. hope this helps..
+ 1
I think you should read this first:
https://scoutapm.com/blog/JUMP_LINK__&&__python__&&__JUMP_LINK-memory-management#:~:text=Heap%20memory,-All%20objects%20and&text=When%20a%20variable%20is%20created,by%20all%20your%20program's%20methods.
+ 1
Generally a stack is storage device that stores information i.e used for memory management,also used for conversion from one form of expression to another form .
+ 1
Yes ,it's used in solving any kind of expression like ,infix, prefix and postfix expressions
+ 1
What is a heap?
+ 1
this is the real life application of stack:
Let's take an example in google Docs we use undo and redo,... Here the last edited element will be removed in undo and the element is replaced in its original place in this way we can use it
I think I've clarified ur doubt if ure still confused open google Docs enter any random line ... the sentence in this line is stored in the form of stack if u press (Ctrl+z) undo-> last element or sentence is popped Likewise undo all the line again redo them u can see that it's following last in first out and first in last out... thx