-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.py
More file actions
38 lines (37 loc) · 841 Bytes
/
linkedlist.py
File metadata and controls
38 lines (37 loc) · 841 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
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())