-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-LinkedList.py
More file actions
28 lines (27 loc) · 680 Bytes
/
15-LinkedList.py
File metadata and controls
28 lines (27 loc) · 680 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
class Node:
def __init__(self,data):
self.data = data
self.next = None
class Solution:
def display(self,head):
current = head
while current:
print(current.data,end=' ')
current = current.next
def insert(self,head,data):
nodeData = Node(data)
if head is None:
head = nodeData
else:
current = head
while current.next:
current = current.next
current.next = nodeData
return head
mylist= Solution()
T=int(input())
head=None
for i in range(T):
data=int(input())
head=mylist.insert(head,data)
mylist.display(head);