Why can’t we “POP” out the 3rd element from the stack or any specific element from the stack?
Stacks and Queues
Stack is a data structure which works on the solo principle of (FILO Order) meaning First In Last Out Order.
Consider this you have 3 coins one of Rs. 1, one of Rs. 2 and one of Rs. 5. First put Rs. 1 coins on a table then above it put the Rs. 2 coin and then Rs. 5 coin. Now can u remove the Rs. 1 coin without removing the Rs. 5 and Rs. 2 coin. The answer is strictly NO. This is what a stack means.
You can only add an element on top of a stack or remove the top element of a stack.
Also poping out the 3rd element means deleting the 3rd element, this means you can pop/delete any element from stack, hence it becomes similar to an array, but then what is the need of studying array and stack seperately.
Reply if you still have any doubt left.
Hey Shashwat, when your doubts are resolved… please mark them as resolved in your course’s Ask Doubt section.
Hi Shashwat, I am marking your doubt as Resolved. Re-open it if required