+ 1

LIFO

Question: A stack is a Last In First Out (LIFO) linear data type that can be imagined as being like a pile of paperwork. New elements can only be added to the top of the stack. Old elements can only be removed from the top of the stack. Elements at the bottom or in the middle of the stack cannot be reached except by removing all the elements above them. Output A: 3 pushed to stack 16 pushed to stack 29 pushed to stack 34 pushed to stack 65 pushed to stack 98 pushed to stack 98 popped from stack 65 popped from stack 34 popped from stack Write a function to implement stack using array that will display the Output A as above. I have no idea how to solve this question since I only know the concept and even I google also couldn't get the code. Can someone help me to solve this question ? :") Thanks a lot

10th Jul 2021, 8:32 AM
DAYU
DAYU - avatar
2 Réponses
+ 1
DAYU Try using a static int variable to keep track of the last index of the array and update it accordingly. I hope that this helps. Edit: Global*
10th Jul 2021, 9:41 AM
Calvin Thomas
Calvin Thomas - avatar