Program:
items=[]
def push(data):
items.append(data)
print("\n\t--->>>",data,"Successfully Push on the Stack\n")
def pop():
lp=items.pop()
print("\n\t--->>>",lp,"is Successfully Pop from the Stack\n")
def peek():
l=len(items)
lp=items[l-1]
print("\n\t--->>>Peek value on Stack is: ",lp,"\n")
def get_stack():
print("\n\t--->>>STACK: ",items,"\n")
push(1)
push(2)
push(3)
push(4)
push(5)
push(6)
get_stack()
peek()
pop()
get_stack()
Expected O/P:
--->>> 1 Successfully Push on the Stack
--->>> 2 Successfully Push on the Stack
--->>> 3 Successfully Push on the Stack
--->>> 4 Successfully Push on the Stack
--->>> 5 Successfully Push on the Stack
--->>> 6 Successfully Push on the Stack
--->>>STACK: [1, 2, 3, 4, 5, 6]
--->>>Peek value on Stack is: 6
--->>> 6 is Successfully Pop from the Stack
--->>>STACK: [1, 2, 3, 4, 5]
items=[]
def push(data):
items.append(data)
print("\n\t--->>>",data,"Successfully Push on the Stack\n")
def pop():
lp=items.pop()
print("\n\t--->>>",lp,"is Successfully Pop from the Stack\n")
def peek():
l=len(items)
lp=items[l-1]
print("\n\t--->>>Peek value on Stack is: ",lp,"\n")
def get_stack():
print("\n\t--->>>STACK: ",items,"\n")
push(1)
push(2)
push(3)
push(4)
push(5)
push(6)
get_stack()
peek()
pop()
get_stack()
Expected O/P:
--->>> 1 Successfully Push on the Stack
--->>> 2 Successfully Push on the Stack
--->>> 3 Successfully Push on the Stack
--->>> 4 Successfully Push on the Stack
--->>> 5 Successfully Push on the Stack
--->>> 6 Successfully Push on the Stack
--->>>STACK: [1, 2, 3, 4, 5, 6]
--->>>Peek value on Stack is: 6
--->>> 6 is Successfully Pop from the Stack
--->>>STACK: [1, 2, 3, 4, 5]
0 Comments
Post a Comment