-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllistInsertInOrder.py
44 lines (44 loc) · 1.03 KB
/
llistInsertInOrder.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
class Node:
def __init__(self,data):
self.data=data
self.next=None
class LinkedList:
def __init__(self):
self.head=None
def push(self,data):
new=Node(data)
new.next=self.head
self.head=new
llist.print()
def insertat(self,newdata,data):
new=Node(data)
last=self.head
while(last.data == newdata):
last=last.next
last=last.next
new.next=last.next
last.next=new
llist.print()
def append(self,data):
new=Node(data)
if self.head is None:
self.head=new
return
last=self.head
while(last.next):
last=last.next
last.next=new
llist.print()
def print(self):
print('\n')
last=self.head
while(last):
print(last.data,end='-->')
last=last.next
if __name__=='__main__':
llist=LinkedList()
llist.append(6)
llist.append(7)
llist.insertat(7,8)
llist.push(9)
llist.print()