-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideo_8_InsertNodeAtEnd.py
More file actions
49 lines (41 loc) · 1.16 KB
/
Video_8_InsertNodeAtEnd.py
File metadata and controls
49 lines (41 loc) · 1.16 KB
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
#Node insert at end of Linked List
class Node:
def __init__(self,data):
self.info=data
self.next=None
class LinkedList:
def __init__(self):
self.head=None
def insbeg(self,ele):
current=Node(ele)
if self.head is None:
self.head=current
else:
current.next=self.head
self.head=current
def insend(self, ele):
new_node = Node(ele)
if self.head is None:
self.head = new_node
else:
current = self.head
while current.next is not None:
current = current.next
current.next = new_node
def display(self):
if self.head is None:
print("Empty Linked List")
return
else:
current=self.head
while current:
print(current.info," -> ", end="")
current=current.next
print("None")
mylist=LinkedList()
n=int(input("How many elements you want to insert"))
for i in range(n):
ele=int(input("Enter element"))
mylist.insend(ele)
print("My linked list")
mylist.display()