-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpyth.py
More file actions
71 lines (57 loc) · 1.35 KB
/
pyth.py
File metadata and controls
71 lines (57 loc) · 1.35 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class createnode:
def __init__(self,data):
self.data=data
self.next=None
class Unordered_list:
def __init__(self):
self.head=None
self.last=None
def createlist(self,data):
node=createnode(data)
if self.head==None:
self.head=node
self.head.next=self.head
self.last=self.head.next
else:
node.next=self.last.next
self.last.next=node
self.last=node
def insertatbegin(self,data):
node=createnode(data)
if self.head==None:
self.head=node
self.head.next=self.head
self.last=self.head.next
else:
node.next=self.last.next
self.last.next=node
self.last=node
head=self.last
def insertatpos(self,data,srchd_data):
node=createnode(data)
temp=self.last.next
while(temp!=self.last):
if(temp.data==srchd_data):
node.next=temp.next
temp.next=node
break
else: temp=temp.next
def printlist(self):
temp=self.last.next
while True:
print(temp.data)
temp=temp.next
if temp==self.last.next:
break;
a=Unordered_list()
a.createlist(10)
a.createlist(20)
a.createlist(30)
a.createlist(45)
a.printlist()
print("Now insert data at begining")
a.insertatbegin(60)
a.printlist()
print("insertion at some position")
a.insertatpos(70,30)
a.printlist()