-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.5.py
More file actions
32 lines (24 loc) · 780 Bytes
/
ex2.5.py
File metadata and controls
32 lines (24 loc) · 780 Bytes
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
import sys
import json
file = open("ex2.json")
unsorted_lists = json.load(file)
reorganized_lists = []
reorganized_list = []
sys.setrecursionlimit(20000)
def func1(arr, low, high):
middle = func2(arr, low, high)
if low <= (middle - 1):
func1(arr, low, middle - 1)
if high >= (middle + 1):
func1(arr, middle + 1, high)
def func2(array, start, end):
middle_index = ((end - start) // 2) + start
reorganized_list.append(array[middle_index])
return middle_index
if __name__ == "__main__":
for list in unsorted_lists:
reorganized_list = []
func1(list, 0, len(list) - 1)
reorganized_lists.append(reorganized_list)
with open("ex2.5.json", "w") as write_file:
json.dump(reorganized_lists, write_file)