-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.py
52 lines (45 loc) · 1.26 KB
/
12.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
class Node:
def __init__(self, data , data1):
self.data1 = data
self.data = data
self.next = None
self.prev = None
class List:
def __init__(self):
self.head = Node(None,None)
self.head.next = self.head
self.head.prev = self.head
self.n = 0
def get(self,ind):
if ind >= self.size() :
raise Exception('Out of list')
x = self.head.next
for i in range(ind) :
x=x.next
return x
def insert_after(self, x, data, data1):
y = Node(data,data1)
self.n += 1
y.prev = x
y.next = x.next
x.next = y
y.next.prev = y
return y
def delete(self, x):
if self.size()==0:
raise Exception('List is empty')
self.n -= 1
x.prev.next = x.next
x.next.prev = x.prev
return x
def find(self, val):
x = self.head.next
for i in range(self.size()) :
if x.data == val :
return x
x=x.next
return None
def size(self):
return self.n
def is_empty(self):
return self.n==0