Skip to content

Commit 79259f4

Browse files
committed
Added comments
1 parent ba01049 commit 79259f4

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

QuickSort.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11

22
def quick_sort(arr):
33

4-
# Check if array is divisable
4+
''' Check if array is divisable else
5+
retrun single element array '''
56
if len(arr)>1:
67

78
start_index = 0
89
end_index = len(arr)
9-
mid_point = int((start_index+end_index)/2)
10-
11-
list1 = list(filter(lambda x : x < arr[mid_point],arr))
12-
list2 = list(filter(lambda x : x > arr[mid_point],arr))
13-
10+
mid_index = int((start_index+end_index)/2)
11+
12+
'''
13+
Divide the array in 2 sub arrays and arrange them as
14+
1 - This will put the mid point in its sorted index
15+
2 - Smaller then mid_point
16+
3 - Greater then mid_point
17+
'''
18+
list1 = list(filter(lambda x : x < arr[mid_index],arr))
19+
list2 = list(filter(lambda x : x > arr[mid_index],arr))
20+
21+
'''Continue division till we get last undivisable element'''
1422
list1 = quick_sort(list1)
23+
1524
list2 = quick_sort(list2)
1625

17-
list1.append(arr[mid_point])
26+
list1.append(arr[mid_index])
1827

28+
'''Append sorted sub arrays and return '''
1929
return(list1+list2)
2030
else:
2131
return arr

0 commit comments

Comments
 (0)