Professional Documents
Culture Documents
Assignment 7
Assignment 7
CODE:
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
self.next = None
def Print(self):
temp = self.head
while (temp):
print(temp.data)
temp = temp.next
l = LinkedList()
n = int(input("Enter The Total nos : "))
for i in range(n):
s = input("\nWhich insert operation you want to do ? : \nAt Begin -- (1)
/ Anywhere -- (2) / At End -- (3) : ")
no = int(input("Enter Any No. : "))
if (s.strip()).lower() == '1' :
l.At_Begin(no)
if (s.strip()).lower() == '2':
p = int(input("Enter The Position of Insertion : "))
l.Insert(no,p-1)
elif (s.strip()).lower() == '3' :
l.At_End(no)
print("\nLinked List after Insertion : ")
l.Print()
g = int(input("\nEnter The No of Elements to be deleted : "))
if g>n:
g = n
for i in range(g):
p = int(input("Enter The Position of Deletion : "))
l.Delete(p-1)
n -= 1
print("Only",n,"Elements are left\n")
print("\nLinked List after Deletion : ")
l.Print()
OUTPUT: