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.
1) Pin code of a city
2) Name of the city
Write a python program to implement the following operations in the above stack.
(a) PUSH() : to push a node onto the stack
(b) POP() : to remove a node from the stack
Program code:
Output:
[{'pin': 842001, 'city': 'Muz'}, {'pin': 110078, 'city': 'Delhi'}, {'pin': 820067, 'city': 'Patna'}] Popped element is {'pin': 820067, 'city': 'Patna'} Popped element is {'pin': 110078, 'city': 'Delhi'} Final List = [{'pin': 842001, 'city': 'Muz'}]
In the above code snippet basic functions of Queue 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