MCPcopy Index your code
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / UnorderedList

Class UnorderedList

Lists.py:24–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23# 定义一个无序链表
24class UnorderedList:
25 def __init__(self):
26 self.head = None
27
28 def isEmpty(self):
29 return self.head == None
30
31 def add(self, item):
32 temp = Node(item)
33 temp.setNext(self.head)
34 self.head = temp
35
36 def size(self):
37 current = self.head
38 count = 0
39 while current != None:
40 count += 1
41 current = current.getNext()
42 return count
43
44 def search(self, item):
45 current = self.head
46 found = False
47 while current != None and not found:
48 if current.getData() == item:
49 found = True
50 else:
51 current = current.getNext()
52 return found
53
54 def remove(self, item):
55 current = self.head
56 previous = None
57 found = False
58 while not found:
59 if current.getData() == item:
60 found = True
61 else:
62 previous = current
63 current = current.getNext()
64
65 if previous == None:
66 self.head = current.getNext()
67 else:
68 previous.setNext(current.getNext())
69
70myList = UnorderedList()
71myList.add(31)

Callers 1

Lists.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected