0% found this document useful (0 votes)
3 views

cs record

The document outlines various Python programs that implement stack data structures using lists, including functionalities for pushing, popping, and displaying elements. It also details methods for reversing strings, converting infix expressions to postfix, and managing employee records through SQL integration. Each section provides a clear aim, algorithm, and steps for implementation, ensuring a comprehensive understanding of stack operations and database interactions.
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 views

cs record

The document outlines various Python programs that implement stack data structures using lists, including functionalities for pushing, popping, and displaying elements. It also details methods for reversing strings, converting infix expressions to postfix, and managing employee records through SQL integration. Each section provides a clear aim, algorithm, and steps for implementation, ensuring a comprehensive understanding of stack operations and database interactions.
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
You are on page 1/ 6

12.

STACK – LIST Implementation

Aim : Write a menu driven program in Python to implement a stack using a list data structure.
Algorithm:

Step 1: Start
Step 2: Create an empty list and three user-defined functions push( ) , pop( ) and disp( ) to insert,
delete and display the elements in the stack.
Push( ):
 Create an empty list and append the data’s in the list using append function
s.append(data)

Pop( ):

 Check whether the stack is empty and print “Stack is Empty”


iflen(s)==0:
print('Stack is empty')

 Delete the last element and display the deleted element using the pop( ) function
dn = s.pop()
Disp( ):

 Display the elements in the stack using the loop statement.


Step 3: Now, create a menu to receive the choice from the user and perform its related operations
by calling the function.

13. STACK – LIST Implementation – Book Details


Aim : Write a menu driven program in Python to implement a stack using a list data structure.
Each node should have • Book no • Book name • Book price

Algorithm:
Step 1: Start
Step 2: Create an empty list and three user-defined functions push( ) , pop( ) and disp( ) to insert,
delete and display the elements in the stack.
Push( ):
o Create an empty list and append the data’s in the list using append function
s.append(data)

Pop( ):

o Check whether the stack is empty and print “Stack is Empty”

iflen(s)==0:
print('Stack is empty')
o Delete the last element and display the deleted element using the pop( ) function
dn = s.pop()
Disp( ):

 Display the elements in the stack using the loop statement.


Step 3: Now, create a menu to receive the choice from the user and perform its related operations by
calling the function.

14. Reversing a String – Stack Method


Aim: Write a python program to reverse a string using stack data
structure
Algorithm:
*. created another function called the reverseString.
 In this function, took the input string as a parameter,
initialized an empty stack, and pushed all the char
 ran a while loop and popped each element of the stack until it
became empty and appended the popped character back to
the string. Finally returned the resultant string, which is the
reversed string of the original one

15. Infix Expression into Postfix Expressions – Stack method
Aim: Write a python program to convert Infix Expression into Postfix Expressions – Stack method
Algorithm:
Following is the list of lowest to highest priority of operators:
Priority 1 ->'' + '', '' - ''
Priority 2 -> '' * '', '' / ''
Priority 3 -> '' ^ ''

Rules:
1. Start by inserting '' ( '' in the stack
2. If character == operand, put in postfix expression
3. If character == operator, put in stack
4. If scanned operator priority (eg '' * '') > top operator priority (eg '' + ''), push in stack
5. If scanned operator priority (eg '' + '') < top operator priority (eg '' * ''), pop till
priority[scanned] becomes > priority[top]
6. If '' ) '' , encountered, pop till '' ( ''

16. STACK – LIST Implementation – Employee Details

Aim:
Write a program to implement a stack for the employee details (empno,
name).

Algorithm:
Step 1: Start
Step 2: Create an empty list and four user-defined functions push( ) , pop( ) display() and isEmpty()
) to insert, delete and display the elements in the stack.
Push( ):
o Create an empty list and append the data’s in the list using append functiong
stk.append(data)

Pop( ):

o Check whether the stack is empty and print “Stack is Empty”


If len(stk)==0:
print('Stack is empty')
o Delete the last element and display the deleted element using the pop( ) function
Stk.pop()
Disp( ):

 Display the elements in the stack using the loop statement.


Step 3: Now, create a menu to receive the choice from the user and perform its related operations by
calling the function.

17.
Aim: Write a Program to integrate SQL with Python by importing the MySQL module and create a record of
employee and display the record.
Algorithm:
Step 1: Start
Step 2: To check the working of python mysql connectivity import the module and connect with the
database.
importmysql.connector

con=mysql.connector.connect(host="localhost",user='root',password="12345",

database="employee")
Step 3: Start querying the database
cur.execute("Create table EMPLOYEE(EMPNO int, NAME varchar(10), DEPARTMENTvarchar(20),
SALARY float)")
Step 4: Input the values in the table and display the result.
Step 5: Stop

18.
Aim: Write a Program to integrate SQL with Python by importing the MYSQL module to search an
employee number in table employee and display record, if empno not found display appropriate
message.
Algorithm:
Step 1: Start
Step 2: To check the working of python mysql connectivity import the module and connect with the
database.
importmysql.connector

con=mysql.connector.connect(host="localhost",user='root',password="12345",

database="svvv")
cur = con.cursor()

Step 3: Enter the employee no to search for and display the details of the Employee
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
Step 4: Stop

19.
Aim: Write a Program to integrate SQL with Python by importing the MYSQL module to update the
employee record of entered empno.

Algorithm:
Step 1: Start
Step 2:To check the working of python mysql connectivity import the module and connect with the
database.
Import mysql.connector

con=mysql.connector.connect(host="localhost",user='root',password="12345",

database="svvv ")
cur = con.cursor()
Step 3: Enter the Emp.No to update the details of the employee.
Step 4: Check for the emp.no and update the new details in the table and commit. Else display the
message "Sorry! Empno not found "
Step 5: Stop
20.
Aim: Program to integrate SQL with Python by importing the MYSQL module to delete therecord of
entered employee number.
Algorithm:
Step 1: Start
Step 2:To check the working of python mysql connectivity import the module and connect with the
database.
Import mysql.connector

con=mysql.connector.connect(host="localhost",user='root',password="12345",

database="svvv ")
cur = con.cursor()
Step 3:Enter the Emp.No to delete the details of that employee.
Step 4: Check if that emp.no exist and delete the details of that particular employee and commit. Else
display the message "Sorry! Empno not found "
Step 5: Stop

You might also like