Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create singlylinklist.py #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions linked_lists/singlylinklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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())