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

Stack

The document outlines a program for managing employee records using a stack data structure, allowing for addition, deletion, and display of employee details. It includes a loop for user interaction to choose operations such as pushing new employee data onto the stack, popping the latest entry, or displaying all entries. Additionally, it describes a function to populate the stack with even numbers from a given list and a function to remove the top element from the stack.

Uploaded by

Rajni Adhikari
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

The document outlines a program for managing employee records using a stack data structure, allowing for addition, deletion, and display of employee details. It includes a loop for user interaction to choose operations such as pushing new employee data onto the stack, popping the latest entry, or displaying all entries. Additionally, it describes a function to populate the stack with even numbers from a given list and a function to remove the top element from the stack.

Uploaded by

Rajni Adhikari
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

Practical Implementation -3 i

Write a program to create a Stack called Employee, to perform the basic operati 0
list. The list contains the two values-emp Ioyee number and employee lia ns on S
·· d I · d d· I f · me· Th taci.~lsi
e Ptograms~
include the options for .add1t1on, e etton an tsp ay o employee detail s. n1
#Program to add , delete and display the records of an Employee us· Ob\
#implementation through stack ing l iat
J:mployee- []
c-"Y"
while (C - "Y" ):
print( "l . PUSH" )
print( "2 . POP" )
print( "3. Display" )
choice-int(inpu t("Enter your choice: " ))
i f (choice - 1):
e_id•input( "Enter Employee no:" )
ename•input( "Enter the employee name : " )
-
u,p •<•id, ename)
B:[Link]~nd (emp)
elif (choice - 2):
if (Bmployee .- []):
print( " stack Empty" )
else :
e_id, ename • [Link]()
print( "Deleted element is: " ,e id,ename)
elif (choice - 3): -
i•len(Bmployee) .
while i> 0: #To display elements from last element to . first
p~int(Bmployee [i-1])
i • i - 1
else :
print( "Wrong Input" )
c-input( "Do you want to continue or not?" )
r - Me d al are",
- -'"' ..A...l..l ..:>[Link] x)
.st of numbers is used ~o pop~late the contents of a Stack using a function push(Stack, data) where Stadt
19. Ah ty list and data ts th.e hstof numbers. The function should push all the numbers that are even to
is an·em:
the stac • Also write the function pop() that removes the top element of the Stack on its each call.
AnS· data -_ [l , 2 , 3,4,5,6,7,8]
stack= [ 1
def pu S h (Stack, data) :
for x in data:
if X % 2 == Q:
[Link](x)
def pop (Stack) :
if len (Stack) ==O:
return "Stack empty"
else:
return [Link]()
push (Stack, data)
print (pop (Stack) )

- Data Structures in Python- - - - - - - - - - - - - - - - - . : . . __ _ __ J. 5.27


L,

You might also like