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,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing