Skip to content

Commit f7780f4

Browse files
committed
added single link list code in python
1 parent d3d05d2 commit f7780f4

File tree

6 files changed

+243
-0
lines changed

6 files changed

+243
-0
lines changed

Data Structures/Linked List/Python/.idea/Python.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Data Structures/Linked List/Python/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Data Structures/Linked List/Python/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Data Structures/Linked List/Python/.idea/workspace.xml

Lines changed: 167 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Node:
2+
3+
def __init__(self, data, nextNode=None):
4+
self.data = data
5+
self.nextNode = nextNode
6+
7+
def getData(self):
8+
return self.data
9+
10+
def setData(self, val):
11+
self.data = val
12+
13+
def getNextNode(self):
14+
return self.nextNode
15+
16+
def setNextNode(self, val):
17+
self.nextNode = val
18+
19+
20+
class LinkedList:
21+
22+
def __init__(self, head=None):
23+
self.head = head
24+
self.size = 0
25+
26+
def getSize(self):
27+
return self.size
28+
29+
def addNode(self, data):
30+
newNode = Node(data, self.head)
31+
self.head = newNode
32+
self.size += 1
33+
return True
34+
35+
def printNode(self):
36+
curr = self.head
37+
while curr:
38+
print(curr.data)
39+
curr = curr.getNextNode()
40+
41+
42+
myList = LinkedList()
43+
print("Inserting")
44+
print(myList.addNode(input()))
45+
print(myList.addNode(input()))
46+
print(myList.addNode(input()))
47+
print("Printing")
48+
myList.printNode()
49+
print("Size")
50+
print(myList.getSize())

contributors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@
4141
39. [Sanka Mohottala] (https://github.com/sankamohottala)
4242
40. [Riya Singh](https://github.com/riya24899)
4343
41. [Your Name](https://github.com/yourusername)
44+
42. [Sarthak gupta](https://github.com/sarthak-g)

0 commit comments

Comments
 (0)