-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlinklist.py
More file actions
48 lines (37 loc) · 942 Bytes
/
linklist.py
File metadata and controls
48 lines (37 loc) · 942 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
45
46
47
48
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
def setNextNode(self,val):
self.nextNode = val
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("Inserting")
print(myList.addNode(5))
print(myList.addNode(15))
print(myList.addNode(25))
print("Printing")
myList.printNode()
print("Size")
print(myList.getSize())