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

CLL Py

Uploaded by

Ms
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)
31 views2 pages

CLL Py

Uploaded by

Ms
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/ 2

class node:

def __init__(self,data):
self.data=data
self.next=None
self.prev=None

class cll:
def __init__(self):
self.head=None
self.tail=None

def display(self):
temp=self.head
if temp==None:
print("linkly list is empty ")
return
while temp:
print(temp.data)
if temp==self.tail:
break
else:
temp=temp.next

def search(self,key):
temp=self.head
if temp==None:
print("Linked list is empty ")
return
while temp:
if temp.data==key:
print("Key found")
break
elif temp==self.tail:
print("Key not found ")
break
else:
temp=temp.next

def append(self,newnode):
if self.head==None:
self.head=newnode
self.tail=newnode
else:
temp=self.tail
temp.next=newnode
newnode.prev=temp
self.tail=newnode
self.tail.next=self.head

def remove(self,key):
temp=self.head
if temp==None:
print("Linked list is empty")
return
while temp:
if temp.data==key:
if self.head==self.tail:
self.head=None
self.tail=None
break
elif temp==self.head:
self.head=temp.next
break
elif temp==self.tail:
self.tail=temp.prev
break
temp=temp.next
if temp==self.head:
print("Key not found")
break

cLL=cll()
while 1:
print("\n 1.Append \t 2.Display \t 3.Search \t 4.Delete
\n")
choice=int(input("Enter your choice : "))
if choice==1:
data=int(input("Enter an element to insert :"))
cLL.append(node(data))
elif choice==2:
cLL.display()
elif choice==3:
key=int(input("Enter key to search : "))
cLL.search(key)
elif choice==4:
key=int(input("Enter key to delete :"))
cLL.remove(key)
else:
break

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