-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-node.py
More file actions
46 lines (39 loc) · 1.13 KB
/
test-node.py
File metadata and controls
46 lines (39 loc) · 1.13 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
class Node:
def __init__(self, data=None):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def AtBegining(self, data_in):
NewNode = Node(data_in)
NewNode.next = self.head
self.head = NewNode
def RemoveNode(self, Removekey):
HeadVal = self.head
# if (HeadVal is not None):
# if (HeadVal.data == Removekey):
# self.head = HeadVal.next
# HeadVal = None
# return
while HeadVal is not None:
if HeadVal.data == Removekey:
break
prev = HeadVal
HeadVal = HeadVal.next
if HeadVal is None:
return
prev.next = HeadVal.next
def LListprint(self):
printval = self.head
while printval:
print(printval.data)
printval = printval.next
if __name__ == '__main__':
llist = LinkedList()
llist.AtBegining("Mon")
llist.AtBegining("Tue")
llist.AtBegining("Wed")
llist.AtBegining("Thu")
llist.RemoveNode("Tue")
llist.LListprint()