A stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). Consider an example of plates stacked over one another in the canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time.
Mainly the following two basic operations are performed in the stack:
Program code:
Output:
Enter your choice:1:Press 1 to Push2:Press 2 to PopYour Option:1Enter element to push on stack:5[4, 5, 6, 7, 5]
Enter your choice:1:Press 1 to Push2:Press 2 to PopYour Option:2The last entered element was popped![4, 5, 6]
In the above code snippet basic functions of stack are demonstrated.
To view all the lessons in chapter 10: http://computertutor.in/class-12-computer-science/chapter-10/
To view entire class 12 computer science study material: http://computertutor.in/resources/
You cannot copy content of this page