Skip to content

Commit 0810918

Browse files
committed
update
1 parent a934522 commit 0810918

File tree

2 files changed

+10
-149
lines changed

2 files changed

+10
-149
lines changed

README.md

Lines changed: 5 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -4,145 +4,6 @@ This is a simple implementation of ArrayList in Python.
44

55
## Functions
66

7-
<!-- def __init__(self, size=10):
8-
self.size = size
9-
self.count = 0
10-
self.items = []
11-
12-
def is_empty(self):
13-
return self.count == 0
14-
15-
def is_full(self):
16-
return self.count == self.size
17-
18-
def add(self, item):
19-
if self.is_full():
20-
raise Exception("List is full")
21-
self.items.append(item)
22-
self.count += 1
23-
24-
def add_at(self, index, item):
25-
if index < 0 or index >= self.size:
26-
raise Exception("Index out of range")
27-
self.items.insert(index, item)
28-
29-
def add_first(self, item):
30-
self.add_at(0, item)
31-
32-
def add_last(self, item):
33-
self.add(item)
34-
35-
def remove_at(self, index):
36-
if index < 0 or index >= self.size:
37-
raise Exception("Index out of range")
38-
del self.items[index]
39-
40-
def remove_first(self):
41-
self.remove_at(0)
42-
43-
def remove_last(self):
44-
self.remove_at(self.count - 1)
45-
46-
def remove(self):
47-
self.remove_last()
48-
49-
def set(self, index, item):
50-
if index < 0 or index >= self.size:
51-
raise Exception("Index out of range")
52-
if index >= self.count:
53-
self.count = index + 1
54-
self[index] = item
55-
56-
57-
def size(self):
58-
return self.count
59-
60-
def clear(self):
61-
self.items = []
62-
self.count = 0
63-
64-
def to_string(self):
65-
return str(self.items)
66-
67-
def __repr__(self):
68-
return str(self.items)
69-
70-
def __contains__(self, item):
71-
return self.contains(item)
72-
73-
def contains(self, item):
74-
return item in self.items
75-
76-
def index_of(self, item):
77-
return self.items.index(item)
78-
79-
def __eq__(self, other):
80-
return self.items == other.items
81-
82-
def __ne__(self, other):
83-
return self.items != other.items
84-
85-
def __lt__(self, other):
86-
return self.items < other.items
87-
88-
def __le__(self, other):
89-
return self.items <= other.items
90-
91-
def __gt__(self, other):
92-
return self.items > other.items
93-
94-
def __ge__(self, other):
95-
return self.items >= other.items
96-
97-
def __add__(self, other):
98-
return self.items + other.items
99-
100-
def __iadd__(self, other):
101-
self.items += other.items
102-
return self
103-
104-
def __isub__(self, other):
105-
self.items -= other.items
106-
return self
107-
108-
def __sub__(self, other):
109-
return self.items - other.items
110-
111-
def __mul__(self, other):
112-
return self.items * other
113-
114-
def __imul__(self, other):
115-
self.items *= other
116-
return self
117-
118-
def __rmul__(self, other):
119-
return self.items * other
120-
121-
def get(self, index):
122-
if index < 0 or index >= self.count:
123-
raise Exception("Index out of range")
124-
return self.items[index]
125-
126-
def __str__(self):
127-
return str(self.items)
128-
129-
def __len__(self):
130-
return len(self.items)
131-
132-
def __iter__(self):
133-
return iter(self.items)
134-
135-
def __getitem__(self, index):
136-
return self.get(index)
137-
138-
def __setitem__(self, index, value):
139-
if index < 0 or index >= self.size:
140-
raise Exception("Index out of range")
141-
self.items[index] = value
142-
143-
def __delitem__(self, index):
144-
del self.items[index] -->
145-
1467
- `add` - Add an element to the end of the list
1478
- `add_at` - Add an element at a specific index
1489
- `remove` - Remove an element from the list
@@ -188,11 +49,11 @@ from ArrayList import ArrayList
18849
list = ArrayList(10)
18950

19051
# Add items to the list
191-
list.insert(1)
192-
list.insert(2)
193-
list.insert(3)
194-
list.insert(4)
195-
list.insert(5)
52+
list.add(1)
53+
list.add(2)
54+
list.add(3)
55+
list.add(4)
56+
list.add(5)
19657

19758
# Print the list
19859
print(list)

example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
list = ArrayList(10)
55

66
# Add items to the list
7-
list.insert(1)
8-
list.insert(2)
9-
list.insert(3)
10-
list.insert(4)
11-
list.insert(5)
7+
list.add(1)
8+
list.add(2)
9+
list.add(3)
10+
list.add(4)
11+
list.add(5)
1212

1313
# Print the list
1414
print(list)

0 commit comments

Comments
 (0)