Linked List Stack Queue File Handling Application
Linked List Stack Queue File Handling Application
def create():
global linked_list
linked_list=list()
n=int(input("How Many nodes: "))
while n>=1:
i=0
el=int(input("Enter Integer Element: "))
linked_list.append(el)
i+=1
n-=1
print("linked_list Created")
def pop():
display()
if(len(linked_list)==0):
print("linked_list empty")
elif (index >=len(linked_list)):
print("Index out of bound")
else:
index=int(input("\nEnter index of Element which you want to delete: "))
linked_list.pop(index)
display()
print("Element deleted")
def push():
display()
index=int(input("\nEnter index where you want to Push New Element: "))
size=len(linked_list)
if (index >=size):
print("Index out of bound")
else:
linked_list.append(0)
while(size>index):
linked_list[size]=linked_list[size-1]
size-=1
el=int(input("Enter element for new node: "))
linked_list[index]=el
display()
print("Element push successfully")
def display():
print("Elements of linked_list")
print("************************")
if(len(linked_list)==0):
print("linked_list is Empty")
else:
for el in linked_list:
print(el,end=" -> ")
def menu():
msg='''
*****************linked_list Application******************
Enter 1 for remove linked_list and create new linked_list
Enter 2 for pop element from linked_list
Enter 3 for push element in linked_list
Enter 4 for display element of linked_list
Enter 5 for Quit linked_list Application
**********************************************************'''
print(msg)
option=int(input("Your Option: "))
if(option==1):
create()
input()
menu()
elif(option==2):
pop()
input()
menu()
elif(option==3):
push()
input()
menu()
elif(option==4):
display()
input()
menu()
elif(option==5):
quit()
else:
print("Enter correct option")
menu()
create()
menu()
# Stack Application
def create():
global stack
stack=list()
n=int(input("How Many nodes: "))
while n>=1:
i=0
el=int(input("Enter Integer Element: "))
stack.append(el)
i+=1
n-=1
print("Stack Created")
def pop():
if(len(stack)==0):
print("stack empty")
else:
stack.pop()
print("Element deleted")
def push():
el=int(input("Enter element for new node: "))
stack.append(el)
print("Element push successfully")
def display():
print("Elements of Stack")
print("*****************")
if(len(stack)==0):
print("Stack is Empty")
else:
for el in stack:
print(el,end=" -> ")
def menu():
msg='''
**********Stack Application**************
Enter 1 for remove stack and create new stack
Enter 2 for pop element from stack
Enter 3 for push element in stack
Enter 4 for display element of stack
Enter 5 for Quit Stack Application
*****************************************'''
print(msg)
option=int(input("Your Option: "))
if(option==1):
create()
input()
menu()
elif(option==2):
pop()
input()
menu()
elif(option==3):
push()
input()
menu()
elif(option==4):
display()
input()
menu()
elif(option==5):
quit()
else:
print("Enter correct option")
menu()
create()
menu()
# Queue Application
def create():
global Queue
Queue=list()
n=int(input("How Many nodes: "))
while n>=1:
i=0
el=int(input("Enter Integer Element: "))
Queue.append(el)
i+=1
n-=1
print("Queue Created")
def pop():
if(len(Queue)==0):
print("Queue empty")
else:
Queue.pop(0)
print("Element deleted")
def push():
el=int(input("Enter element for new node: "))
Queue.append(el)
print("Element push successfully")
def display():
print("Elements of Queue")
print("*****************")
if(len(Queue)==0):
print("Queue is Empty")
else:
for el in Queue:
print(el,end=" -> ")
def menu():
msg='''
**********Queue Application**************
Enter 1 for remove Queue and create new Queue
Enter 2 for pop element from Queue
Enter 3 for push element in Queue
Enter 4 for display element of Queue
Enter 5 for Quit Queue Application
*****************************************'''
print(msg)
option=int(input("Your Option: "))
if(option==1):
create()
input()
menu()
elif(option==2):
pop()
input()
menu()
elif(option==3):
push()
input()
menu()
elif(option==4):
display()
input()
menu()
elif(option==5):
quit()
else:
print("Enter correct option")
menu()
create()
menu()
#File Handling Application
def update():
foia=open("student.csv","a")
print("Hi, \"student.csv\" file ready for update")
regno=int(input("Enter Student Reistration No: "))
name=input("Enter Name of Student: ")
clas=input("Enter Class & Stream/ Section: ")
city=input("Enter City of Student: ")
age=int(input("Enter Age of Student : "))
rec=[regno,name,clas,city,age]
foia.write("\n")
foia.write(str(rec))
print("Record Saved")
foia.close()
def display():
foir=open("student.csv","r")
f=foir.read()
print("****All Contents of student.csv file****")
print(f)
foir.close()
def remove_file():
import os
print("student.csv file will remove permanently from disk")
choice=input("Are you sure to continue(Y/N): ")
if(choice=='y' or choice=='Y'):
if(os.path.exists("student.csv")):
os.remove("student.csv")
print("student.csv file removed")
else:
print("student.csv file not Found")
else:
menu()
def create_new():
print("All Contents of student.csv file will delete permanently")
choice=input("Are you sure to continue(Y/N): ")
if(choice=='y' or choice=='Y'):
foiw=open("student.csv","w")
print("student.csv, file created")
foiw.close()
else:
menu()
def menu():
msg='''
******** File Handling Application *******
********File Name: student.csv ***********
Enter 1 for Create New file in disk
Enter 2 for Add New Record in file
Enter 3 for Dispaly Records of file
Enter 4 for Remove the file from disk
Enter 5 for Quit Application
******************************************'''
print(msg)
op=int(input("Enter Your Option: "))
if(op==1):
create_new()
input("Press Any Key to continue: ")
menu()
elif(op==2):
update()
input("Press Any Key to continue: ")
menu()
elif(op==3):
display()
input("Press Any Key to continue: ")
menu()
elif(op==4):
remove_file()
input("Press Any Key to continue: ")
menu()
elif(op==5):
quit()
else:
print("Ooopss!!!, You entered Wrong Option")
input("Press Any Key to continue: ")
menu()
menu()