-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlloper.py
More file actions
55 lines (54 loc) · 1.26 KB
/
lloper.py
File metadata and controls
55 lines (54 loc) · 1.26 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
class node:
def __init__(self,data):
self.data=data
self.next=None
class sll:
def __init__(self):
self.head=None
def insertatbeg(self,data):
if self.head==None:
self.head=node(data)
else:
new=node(data)
new.next=self.head
self.head=new
def insertatend(self,data):
if self.head==None:
self.head=node(data)
else:
new=node(data)
i=self.head
while i.next:
#i.next!=None
i=i.next
i.next=new
def printing(self):
i=self.head
while i:
print(i.data)
i=i.next
def findlength(self):
count=0
i=self.head
while i:
count+=1
i=i.next
return count
def reversing(slef):
prev=None
current=self.head
next=self.head.next
while current:
current.next=prev
prev=current
current=next
if next:
next=next.next
self.head=prev
l=[1,2,3,4,5]
o=sll()
for i in l:
o.insertatbeg(i)
o.insertatend(i)
o.printing()
print(o.findlength())