-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day_57.py
53 lines (39 loc) · 1.2 KB
/
Day_57.py
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
52
53
"""
DAY 57 : Print elememts of a Linkedlist.
QUESTION : Print all elements of a Linked List where we take linked list as input and print the
linked list in a single line.
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)
Constraints:
1 <= N <= 100
"""
class Node:
def __init__(self, data):
self.data = data
self.next = None
class Linkedlist:
def __init__(self):
self.head = None
def AtEnd(self, newdata):
NewNode = Node(newdata)
if self.head is None:
self.head = NewNode
return
last_ele = self.head
while(last_ele.next):
last_ele = last_ele.next
last_ele.next = NewNode
def printlist(self):
temp = self.head
while temp:
print(temp.data, end=" ")
temp = temp.next
if __name__ == '__main__':
LList = Linkedlist()
enter_more = 'y'
user_input = None
while enter_more=='y' or enter_more == 'Y':
user_input = int(input("Enter Element: "))
enter_more = input("Want to enter more elements(y/n) :")
LList.AtEnd(user_input)
LList.printlist()