We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36a9888 commit 3bd4fcbCopy full SHA for 3bd4fcb
HackerRank/Linked Lists/insert-at-beginning.py
@@ -0,0 +1,31 @@
1
+class node:
2
+ def __init__(self,data):
3
+ self.data=data
4
+ self.next=None
5
+class LinkedList:
6
+ def __init__(self):
7
+ self.start=None
8
+ def display(self):
9
+ if self.start==None:
10
+ print('list is empty')
11
+ else:
12
+ temp=self.start
13
+ while temp:
14
+ print(temp.data)
15
+ temp=temp.next
16
+ def InsertAtHead(self,n):
17
+ if self.start is None:
18
+ self.start=node(n)
19
20
21
22
+ self.start.next=temp
23
+l=LinkedList()
24
+for i in range(int(input())):
25
+ n=int(input())
26
+ if i==0:
27
+ l.start=node(n)
28
+ ptr=l.start
29
30
+ ptr.next=node(n)
31
+ ptr=ptr.next
0 commit comments