-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path15 th day: Linked List
51 lines (39 loc) · 1.08 KB
/
15 th day: Linked List
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
45
46
47
48
49
50
51
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):
if head is None:
head = Node(data)
else:
current = head
while current.next:
current = current.next
current.next = Node(data)
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);
Sample Input
The following input is handled for you by the locked code in the editor:
The first line contains T, the number of test cases.
The
subsequent lines of test cases each contain an integer to be inserted at the list's tail.
4
2
3
4
1
Sample Output
The locked code in your editor prints the ordered data values for each element in your list as a single line of space-separated integers:
2 3 4 1