The structure of a linked list is a collection of items , Each of these items maintains its relative position relative to the others .

python Common functions of linked list  

  A simple item
class Node: # Linked list item , Must contain a value , And the next item , And corresponding set get method def __init__(self,initdata):
self.data = initdata self.next = None def getData(self): return self.data def
getNext(self): return self.next def setData(self,newdata): self.data = newdata
def setNext(self,newnext): self.next = newnext
A linked list
class UnorderedList: def __init__(self): self.head = None def isEmpty(self):
return self.head == None def add(self,item): item1 = Node(item)
item1.setNext(self.head) self.head = item1 def size(self): current = self.head
count = 0 while current != None: count = count + 1 current = current.getNext()
return count def exist(self,item): current = self.head found = False while
current != None and not found : if current.getData() == item: found = True
else: current = current.getNext() return found def show_all(self): current =
self.head show_list = [] while current is not None:
show_list.append(current.getData()) current = current.getNext()
print(show_list) def delete_item(self,item): parent = None current = self.head
found = False while current is not None and not found : if current.getData() ==
item: found = True else: parent = current current = current.getNext() if found:
if parent is None: parent = self.head else: parent.next = current.getNext() udl
= UnorderedList() for i in range(10): udl.add(i) udl.show_all()
print(udl.exist(11)) udl.delete_item(7) udl.show_all()

Technology
©2019-2020 Toolsou All rights reserved,
VUE+Canvas Achieve desktop Pinball brick elimination games C/C++ Memory model 2019PHP Interview questions ( Continuously updated )PHPspringboot2 Separation of front and rear platforms ,token Put in header Pit for verification Vue SpringBoot conduct Excel download element-ui Step on pit record 45 The 12-year-old programmer was turned down , Is the workplace wrong ?Python Web frame Pandas Fundamentals of statistical analysis _ data processing (DataFrame Common operations )Java Misunderstanding —— Method overloading is a manifestation of polymorphism ?