DATA STRUCTURES
4.1 STACKS AND QUEUES |
|
DATA STRUCTURES
4.1 STACKS AND QUEUES |
|
With a LIFO stack the last item of data in to the stack is always the first item of data out. To illustrate this, imagine piling books on top of each other, the last book you placed(at the top of the pile) is the first book you will pick up, even if you want to read the book from the bottom of the pile you would need to remove (pop) each book above it first. This is known as Last In First Out (LIFO)
|
myStack = [] myStack.append("Bob") myStack.append("Jill") myStack.append("Jane") print (myStack)
myStack = ["Bob","Jane","Jill"] myStack.pop() print(myStack)
myStack = [] if not myStack: print ("The Stack is Empty")
myQueue = [] myQueue.append("Bob") myQueue.append("Jill") myQueue.append("Jane") print (myQueue)
myStack = ["Bob","Jane","Jill"] myStack.pop(0) print(myStack)
myQueue = [] if not myQueue: print ("The Queue is Empty")
|
POLISH NOTATION (A-LEVEL ONLY)
|
|
SUGGESTIONS
We would love to hear from you |
SUBSCRIBE
To enjoy more benefits |