-
Notifications
You must be signed in to change notification settings - Fork 6
/
08-list.py
29 lines (24 loc) · 788 Bytes
/
08-list.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
class List:
def __init__(self, size):
if size > 0:
self.the_array = size * [None]
self.count = 0
def length(self):
return self.count
def is_empty(self):
return self.count == 0
def is_full(self):
return self.count >= len(self.the_array)
def add(self, new_item):
has_space_left = not self.is_full()
if has_space_left:
self.the_arrray[self.count] new_item
self.count += 1
return has_space_left
def delete(self, index):
valid_index = index >= 0 and index < self.count
if valid_index:
for i in range(index, self.count-1):
self.the_array[i] = self.the_array[i+1]
self.count -= 1
return valid_index