by Osama M. Khaled last modified 2022-06-18T00:18:42+01:00

Stack concept is easy to understand

Questions #: 4
Pass Score: 80.0%


You can think of a stack as a list that has some operation restrictions where you can insert and delete at only one end of the list. LIFO is last in, first out, this is how the stack treats the elements it contains. The fundamental operations of the stack are push, pop and top. Push is the same as an insert but allows insertion only at the top of the stack. Top gets the last element inserted while pop removes the last element inserted.

Sometimes pop and top can be combined but they are still separate operations.
Usually you get stack underflow exception if you tried to pop from an empty stack and you get a stack overflow exception when you try to push into a full stack. In the below diagram, in order to get A, you need to pop C and then pop B and after that the last element in the stack is A.


    A stack is a list with some restricted operations


    You can get an element which is positioned in the middle of a stack without touching the top elements


    You can push an an element directly to the bottom of a stack


    LIFO stands for

    Last Input First Output
    Last In First Out
    Last Inner First Outer
    Last Index First Object