CS Practical
CS Practical
# List se stack bana rhe h aur if not se hum check krenge ki stack h ya nhi kahi
stack empty to nhi h
#push me hume last me element add krna padta h islie append use kr rhe h aur 2
parameter islie h kyuki btana padega ki kya dalna h aur kaha dalna h
#pop me pop function hi use hoga and use phele hume check krna hoga ki stack exist
krta h ya nhi uske lie hum if not use krenge ye humne push me islie use nhi kia
kyuki agar stack nhi h to element add krke bana sakte h hum but pop me aisa hi kr
sakte
#peek or display same nhi h isme humm pura stack dekh sakte h aur peek me only last
element Jayda farq nhi h bss index pe [-1] laga dena h isse vo last element show
krega agar peek bole to element ka index change krna h aur aagr display bole to []
ese chod dena h isse pura stack show kr dega
class Stack:
def __init__(self):
self.stack = []
def pop(self):
if not self.is_empty():
item = self.stack.pop()
print(f"{item} popped from stack")
return item
else:
print("Stack is empty")
def display(self):
if not self.is_empty():
print("Stack elements:", self.stack)
else:
print("Stack is empty")
def is_empty(self):
return len(self.stack) == 0
def peek(self):
if not self.is_empty():
item = self.stack[-1]
print(f"Top item is: {item}")
return item
else:
print("Stack is empty")
if choice == '1':
item = input("Enter item to push: ")
stack.push(item)
elif choice == '2':
stack.pop()
elif choice == '3':
stack.display()
elif choice == '4':
stack.peek()
elif choice == '5':
print("Exiting...")
break
else:
print("Invalid choice, please try again.")
# Code ko run krenge function ko call krke aur function vo user output wala hi use
hoga
menu()
(A) To display the ECODE, ENAME & DESIG of all employees in descending order of
DOJ.
(B) To display NAME and DESIG of those employees whose SALGRADE is either S02 or
S03.
(C) To display the ENAME, SGRADE AND SALARY of EMPLOYEE’s table, whose DOJ is in
between ’09-JUN-2006’ and ’13-AUG-2009’.
(D) To add a new row with the following content: 109, ‘Monish Roy’, ‘S02’, ’9-sep-
2007’, ’21-Apr-1983’.