- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAddingNodeToStart.py
More file actions
Latest commit
44 lines (36 loc) · 912 Bytes
/
Copy pathAddingNodeToStart.py
File metadata and controls
44 lines (36 loc) · 912 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
'''
Done By -> Anand Kothari
'''
classNode:
def__init__(self,value=None):
self.value=value
self.nextvalue=None
classlinkedList:
def__init__(self):
self.head=None
# Print the linked list
defprintList(self):
thisvalue=self.head
whilethisvalue:
print(thisvalue.value)
thisvalue=thisvalue.nextvalue
definertAtBegining(self,newValue):
newData=Node(newValue)
newData.nextvalue=self.head# Update the new nodes next val to existing node
self.head=newData
list=linkedList()
list.head=Node("Mon")
list2=Node("Tue")
list3=Node("Wed")
list.head.nextvalue=list2
list2.nextvalue=list3
print('''
Before Adding a Node:
'''
)
list.printList()
print('''
After adding a Node in the start:
''')
list.inertAtBegining("Sun") # This Node will be added in the start
list.printList()