classNode:def __init__(self,initdata):
self.data=initdata
self.next=NonedefgetData(self):returnself.datadefgetNext(self):returnself.nextdefsetData(self,newdata):
self.data=newdatadefsetNext(self,newnext):
self.next=newnextclassUnorderedList:def __init__(self):
self.head=NonedefisEmpty(self):return self.head ==Nonedefadd(self,item):
temp=Node(item)
temp.setNext(self.head)
self.head=tempdefsize(self):
current=self.head
count=0while current !=None:
count=count+1current=current.getNext()returncountdefsearch(self,item):
current=self.head
found=Falsewhile current!-None and notfoune:if current.getData() ==item:
found=Trueelse:
current=current.getNext()returnfounddefremove(self,item):
current=self.head
previous=None
found=Falsewhile notfound:if current.getData()==item:
found=Trueelse:
previous=current
current=current.getNext()if previous==None:
self.head=current.getNext()else:
previous.setNext(current.getNext())classOrderedList:def __init__(self):
self.head=NonedefisEmpty(self):return self.head ==Nonedefsize(self):
current=self.head
count=0while current !=None:
count=count+1current=current.getNext()returncountdefremove(self,item):
current=self.head
previous=None
found=Falsewhile notfound:if current.getData()==item:
found=Trueelse:
previous=current
current=current.getNext()if previous==None:
self.head=current.getNext()else:
previous.setNext(current.getNext())defsearch(self,item):
current=self.head
found=False
stop=Falsewhile current!=None and not found and notstop:if current.getData()==item:
found=Trueelse:if current.getData()>item:
stop=Trueelse:
current=current.getNext()returnfounddefadd(self,item):
current=self.head
previous=None
stop=Falsewhile current!=None and notstop:if current.getData()>item:
stop=Trueelse:
previous=current
current=current.getNext()
temp=Node(item)if previous==None:
temp.setNext(self.head)
self.head=tempelse:
temp.setNext(current)
previous.setNext(temp)