0% found this document useful (0 votes)
3 views2 pages

Stack Implementation Using Lists

Uploaded by

rushda.7369
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Stack Implementation Using Lists

Uploaded by

rushda.7369
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM 15

IMPLEMENT A STACK USING LIST

OBJECTIVE:

To write a program to implement the basic operation of a stack, such as adding element

(PUSH operation), removing element (POP operation) and displaying the stack elements

(Traversal operation) using lists.

CODING:

def push(s,item):

[Link](item)

def pop(s):

if s == []:

print('Underflow')

else:

val = [Link]()

print(val)

def show(s):

if s == []:

print("Stack is Empty")

else:

print(s[-1], '<-- Top')

for i in s[-2: : -1]:

print(i)
s=[]

while True:

print("Stack implementation using list")

print("1 : PUSH ")

print("2 : POP ")

print("3 : SHOW ")

print("0 : EXIT " )

ch = int(input("Enter choice: "))

if ch == 1:

val = int(input("Enter a number to push"))

push(s, val)

elif ch == 2:

pop(s)

elif ch == 3:

show(s)

elif ch == 0:

break

RESULT:

The program was executed and output obtained successfully.

You might also like