-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_logicInPython.py
More file actions
58 lines (45 loc) · 1.61 KB
/
test_logicInPython.py
File metadata and controls
58 lines (45 loc) · 1.61 KB
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
53
54
55
56
57
58
def sortFloatsByInteger(input_list):
print("i am in the second function now")
int_values = [int(num) for num in input_list]
min_value = int(min(int_values))
max_value = int(max(int_values))
sorted_dict = {}
for num in input_list:
int_part = int(num)
if int_part not in sorted_dict:
sorted_dict[int_part] = []
sorted_dict[int_part].append(num)
sorted_list = []
for num in range(min_value, max_value + 1):
if num in sorted_dict:
insertion_sort(sorted_dict[num])
sorted_list.extend(sorted_dict[num])
return sorted_list
def insertion_sort(L):
for i, value in enumerate(L):
for j in range(i - 1, -1, -1):
if L[j] > value:
L[j + 1] = L[j]
L[j] = value
return L
def customSort(input_arr):
try:
min_value = min(input_arr)
max_value = max(input_arr)
# Create a dictionary to represent the sparse array
sparse_array = {}
# Populate the sparse array
for num in input_arr:
if num in sparse_array:
sparse_array[num] += 1
else:
sparse_array[num] = 1
# Generate the sorted output
sorted_output = []
for num in range(min_value, max_value + 1):
if num in sparse_array:
sorted_output.extend([num] * sparse_array[num])
return sorted_output
except (ValueError, TypeError):
# Handle the case where input_arr contains floats
return sortFloatsByInteger(input_arr)