-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.py
37 lines (30 loc) · 1.26 KB
/
sort.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
def sortNumbers(data, condition):
if condition == "ASC":
for i in range(len(data) - 1, 0, -1):
for j in range(i):
if data[j] > data[j + 1]:
data[j], data[j + 1] = data[j + 1], data[j]
return data
elif condition == "DESC":
for i in range(len(data) - 1, 0, -1):
for j in range(i):
if data[j] < data[j + 1]:
data[j], data[j + 1] = data[j + 1], data[j]
return data
def sortData(weights, data, condition):
if len(weights) != len(data):
raise ValueError("Invalid input data")
if condition == 'ASC':
for i in range(len(data) - 1, 0, -1):
for j in range(i):
if weights[j] > weights[j + 1]:
weights[j], weights[j + 1] = weights[j + 1], weights[j]
data[j], data[j + 1] = data[j + 1], data[j]
return data
elif condition == 'DESC':
for i in range(len(data) - 1, 0, -1):
for j in range(i):
if weights[j] < weights[j + 1]:
weights[j], weights[j + 1] = weights[j + 1], weights[j]
data[j], data[j + 1] = data[j + 1], data[j]
return data