-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkedListOOP SearchDeleteMissing.py
More file actions
81 lines (73 loc) · 2.98 KB
/
Copy pathLinkedListOOP SearchDeleteMissing.py
File metadata and controls
81 lines (73 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class Node:
def __init__(self, data='', nextPointer =-1):
self.data = data
self.nextP = nextPointer
class linkedList:
def __init__(self, size=12):
#implement class object
self.size = size
self.thisList = [Node() for x in range (self.size)]
for x in range(self.size-1):
self.thisList[x].nextP=x+1
#self.thisList[self.size-1].nextP=-1
self.__freeListPtr = 0
self.__startPointer = -1
def getNextFree(self):
return self.__freeListPtr
def dump(self):
print('startPtr: ', self.__startPointer)
print('freelist: ', self.__freeListPtr)
for x in range(self.size):
print(x, end = ' ')
print(self.thisList[x].data, end=' ')
print(self.thisList[x].nextP)
def insert(self, s):
nextFree = getNextFree()
if nextFree == 0:
print('List is full')
else:
Node[nextFree].Data = s
if start == 0:
start = nextFree
temp = Node[nextFree].link
Node[nextFree].link =0
nextFree = Temp
else:
#traverse the list - starting at start to find
# the positio at which to insert the new item
Temp = Node[nextFree].link
if s < Node[start].data:
#new item will become the start of the list
nodeNext[free].link = start
start = nextFree
nextFree.Temp
else:
#the new item is not at the start of the list
previous = 0
current = start
found = False
while found == False and current !=0:
if s <= Node[current].data:
Node[previous].link = nextFree
Node[nextFree].link = current
found = True
else:
nextFree = Temp
#move to the next node
previous = current
current = Node[current].link
if current==0:
Node[previous].link = nextFree
Node[nextFree].link = 0
nextFree = Temp
def delete(self, s):
pass
def printAll(self):
thisPtr = self.__startPointer
while self.thisList[self.__startPointer].nextP != -1:
print(self.__thisList[thisPtr])
thisPtr+=1
myList = linkedList()
myList.insert('faheem')
myList.dump()
myList.printAll()