Skip to content

Commit 623946b

Browse files
removed unused attrivute
1 parent 24e2e3f commit 623946b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

‎main.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ def __init__(self, size=600):
2323

2424
def genList(self):
2525
self.list = [random.randint(1, 100) for _ in range(self.bars)]
26-
self.len_list = len(self.list)
2726
self.sorted_list = sorted(self.list)
2827
self.reverse_list = sorted(self.list, reverse=True)
29-
self.bar_spacing = self.width / self.len_list
28+
self.bar_spacing = self.width / self.bars
3029
self.bar_width = ceil(self.bar_spacing)
3130
self.bar_height = (self.height - self.top_pad) // max(self.list)
3231

@@ -134,8 +133,8 @@ def drawList(self, clear_bg=False):
134133
x = i * self.bar_spacing
135134
y = self.height - val * self.bar_height
136135
color = (
137-
(self.sorted_list.index(val) + 1) / self.len_list * 255,
138-
(self.reverse_list.index(val) + 1) / self.len_list * 255,
136+
(self.sorted_list.index(val) + 1) / self.bars * 255,
137+
(self.reverse_list.index(val) + 1) / self.bars * 255,
139138
255,
140139
)
141140
pygame.draw.rect(
@@ -147,8 +146,8 @@ def drawList(self, clear_bg=False):
147146

148147
# Algorithms
149148
def bubbleSort(self):
150-
for i in range(self.len_list - 1):
151-
for j in range(self.len_list - 1 - i):
149+
for i in range(self.bars - 1):
150+
for j in range(self.bars - 1 - i):
152151
num1 = self.list[j]
153152
num2 = self.list[j + 1]
154153
if (num1 > num2 and self.ascending) or (
@@ -158,7 +157,7 @@ def bubbleSort(self):
158157
yield True
159158

160159
def insertionSort(self):
161-
for i in range(1, self.len_list):
160+
for i in range(1, self.bars):
162161
current = self.list[i]
163162
while True:
164163
ascending_sort = i > 0 and self.list[i - 1] > current and self.ascending
@@ -174,7 +173,7 @@ def insertionSort(self):
174173
# TODO descending functionality https://www.geeksforgeeks.org/merge-sort/
175174
def mergeSort(self, start=0, end=False):
176175
if not end:
177-
end = self.len_list
176+
end = self.bars
178177
if end - start > 1:
179178
middle = (start + end) // 2
180179

0 commit comments

Comments
 (0)