-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedList.py
53 lines (45 loc) · 1.61 KB
/
linkedList.py
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
class Node:
def __init__(self, phoneNum, msg, timeToText, next = None):
self.phoneNum = phoneNum
self.msg = msg
self.timeToText = timeToText
self.next = None
class ListOfNumbers:
def __init__(self):
self.root = None
def add(self, phoneNum, msg, timeToText):
newNode = Node(phoneNum, msg, timeToText, None)
if (self.root == None) or (self.root.timeToText >= newNode.timeToText):
newNode.next = self.root
self.root = newNode
return
curNode = self.root
while(curNode.next != None) and (curNode.next.timeToText < newNode.timeToText):
curNode = curNode.next
newNode.next = curNode.next
curNode.next = newNode
def remove(self, phoneNum):
if(self.root == None):
return -1
if(self.root.phoneNum == phoneNum):
self.root = self.root.next
return 1
curNode = self.root
while(curNode.next != None):
if curNode.next.phoneNum == phoneNum:
curNode.next = curNode.next.next
return 1
curNode = curNode.next
return -1
def removeFirst(self):
self.root = self.root.next
return
def getFirst(self):
return self.root
def printList(self):
curNode = self.root
print("Now Printing")
while(curNode != None):
print("%s phoneNum %s time %s message" % (str(curNode.phoneNum), str(curNode.timeToText), str(curNode.msg)))
curNode = curNode.next
print("")