-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSinglyLinkedT1.py
More file actions
44 lines (37 loc) · 877 Bytes
/
SinglyLinkedT1.py
File metadata and controls
44 lines (37 loc) · 877 Bytes
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
class Node:
def __init__(self, data, nextNode=None):
self.data = data
self.nextNode = nextNode
def getData(self):
return self.data
def setData(self, val):
self.data = val
def getNextNode(self):
return self.nextNode
class LinkedList:
def __init__(self, head = None):
self.head = head
self.size = 0
def getSize(self):
return self.size
def addNode(self, data):
newNode = Node(data, self.head)
self.head = newNode
self.size+=1
return True
def printNode(self):
curr = self.head
while curr:
print(curr.data)
curr = curr.getNextNode()
myList = LinkedList()
print("Insert values")
print(myList.addNode(76))
print(myList.addNode(20))
print(myList.addNode(7))
print(myList.addNode(89))
print(myList.addNode(92))
print("Printings")
myList.printNode()
print("Size")
print(myList.getSize())