Stack Basic CODING IN PYTHON
CODE:
stack=[]
stack.append("a")
stack.append("b")
stack.append("c")
print("Initial stack")
print(stack)
print(stack.pop())
print(stack.pop())
print(stack.pop())
print(stack)
OUTPUT:
Initial stack ['a', 'b', 'c'] c b a []
CODE:
from collections import deque
stack = deque()
stack.append("a")
stack.append("b")
stack.append("c")
print("intial stack")
print(stack)
print(stack.pop())
print(stack.pop())
print(stack.pop())
print(stack)
OUTPUT:
intial stack deque(['a', 'b', 'c']) c b a deque([])
CODE:
from queue import LifoQueue
stack=LifoQueue(maxsize=3)
print(stack.qsize())
stack.put("a")
stack.put("b")
stack.put("c")
print("Full",stack.full())
print("Size",stack.qsize())
print(stack.get())
print(stack.get())
print(stack.get())
print("Empty",stack.empty())
OUTPUT:
0 Full True Size 3 c b a Empty True
Comments
Post a Comment