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

CS Practical

The document provides a Python implementation of a stack using a list, detailing methods for pushing, popping, displaying, checking if the stack is empty, and peeking at the top element. Additionally, it includes SQL queries for retrieving and manipulating employee data from a database, such as displaying employee details, filtering by salary grade, and inserting a new employee record. The main program presents a menu for user interaction with the stack operations.

Uploaded by

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

CS Practical

The document provides a Python implementation of a stack using a list, detailing methods for pushing, popping, displaying, checking if the stack is empty, and peeking at the top element. Additionally, it includes SQL queries for retrieving and manipulating employee data from a database, such as displaying employee details, filtering by salary grade, and inserting a new employee record. The main program presents a menu for user interaction with the stack operations.

Uploaded by

rajaharsh485
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Python Program to Implement Stack Using a List

# 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 push(self, item):


self.stack.append(item)
print(f"{item} pushed to 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")

# Main program jo user ko output ke form me dikhega


def menu():
stack = Stack()
while True:
print("\nMenu:")
print("1. Push")
print("2. Pop")
print("3. Display:")
print("4. Peek:")
print("5. Exit")
choice = input("Enter your choice: ")

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.

SELECT ECODE, NAME AS ENAME, DESIG


FROM EMPLOYEE
ORDER BY DOJ DESC;

(B) To display NAME and DESIG of those employees whose SALGRADE is either S02 or
S03.

SELECT NAME, DESIG


FROM EMPLOYEE
WHERE SGRADE IN ('S02', '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’.

SELECT E.NAME AS ENAME, E.SGRADE, S.SALARY


FROM EMPLOYEE E
JOIN SALGRADE S ON E.SGRADE = S.SGRADE
WHERE E.DOJ BETWEEN '2006-06-09' AND '2009-08-13';

(D) To add a new row with the following content: 109, ‘Monish Roy’, ‘S02’, ’9-sep-
2007’, ’21-Apr-1983’.

INSERT INTO EMPLOYEE (ECODE, NAME, DESIG, SGRADE, DOJ, DOB)


VALUES (109, 'Monish Roy', 'S02', '9-SEP-2007', '21-APR-1983');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy