Skip to content

Commit 804c1c8

Browse files
committed
Refactored
1 parent 506af46 commit 804c1c8

File tree

29 files changed

+82
-82
lines changed

29 files changed

+82
-82
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def quickSort(alist):
2+
quickSortHelper(alist,0,len(alist)-1)
3+
4+
def quickSortHelper(alist,first,last):
5+
if first<last:
6+
7+
splitpoint = partition(alist,first,last)
8+
9+
quickSortHelper(alist,first,splitpoint-1)
10+
quickSortHelper(alist,splitpoint+1,last)
11+
12+
13+
def partition(alist,first,last):
14+
pivotvalue = alist[first]
15+
16+
leftmark = first+1
17+
rightmark = last
18+
19+
done = False
20+
while not done:
21+
22+
while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
23+
leftmark = leftmark + 1
24+
25+
while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
26+
rightmark = rightmark -1
27+
28+
if rightmark < leftmark:
29+
done = True
30+
else:
31+
temp = alist[leftmark]
32+
alist[leftmark] = alist[rightmark]
33+
alist[rightmark] = temp
34+
35+
temp = alist[first]
36+
alist[first] = alist[rightmark]
37+
alist[rightmark] = temp
38+
39+
40+
return rightmark
41+
42+
alist = [54,26,93,17,77,31,44,55,20]
43+
quickSort(alist)
44+
print(alist)
+37-44
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
1-
def quickSort(alist):
2-
quickSortHelper(alist,0,len(alist)-1)
3-
4-
def quickSortHelper(alist,first,last):
5-
if first<last:
6-
7-
splitpoint = partition(alist,first,last)
8-
9-
quickSortHelper(alist,first,splitpoint-1)
10-
quickSortHelper(alist,splitpoint+1,last)
11-
12-
13-
def partition(alist,first,last):
14-
pivotvalue = alist[first]
15-
16-
leftmark = first+1
17-
rightmark = last
18-
19-
done = False
20-
while not done:
21-
22-
while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
23-
leftmark = leftmark + 1
24-
25-
while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
26-
rightmark = rightmark -1
27-
28-
if rightmark < leftmark:
29-
done = True
30-
else:
31-
temp = alist[leftmark]
32-
alist[leftmark] = alist[rightmark]
33-
alist[rightmark] = temp
34-
35-
temp = alist[first]
36-
alist[first] = alist[rightmark]
37-
alist[rightmark] = temp
38-
39-
40-
return rightmark
41-
42-
alist = [54,26,93,17,77,31,44,55,20]
43-
quickSort(alist)
44-
print(alist)
1+
def quickSort(arr):
2+
"""Apply quick sort on the given array
3+
4+
:param arr: the array to sort
5+
:type arr: list
6+
"""
7+
less = []
8+
pivotList = []
9+
more = []
10+
if len(arr) <= 1:
11+
return arr
12+
else:
13+
pivot = arr[0]
14+
for i in arr:
15+
if i < pivot:
16+
less.append(i)
17+
elif i > pivot:
18+
more.append(i)
19+
else:
20+
pivotList.append(i)
21+
less = quickSort(less)
22+
more = quickSort(more)
23+
return less + pivotList + more
24+
25+
# Unit test
26+
a = [4, 65, 2, -31, 0, 99, 83, 782, 1] # The array to sort
27+
a = quickSort(a)
28+
assert all(a[i] <= a[i+1] for i in range(len(a)-1)) # Assert array is sorted
29+
30+
# Quick sort: Quicksort is a comparison sort, meaning that it can
31+
# sort items of any type for which a "less-than" relation is defined.
32+
# In efficient implementations it is not a stable sort, meaning
33+
# that the relative order of equal sort items is not preserved.
34+
# Quicksort can operate in-place on an array, requiring small
35+
# additional amounts of memory to perform the sorting. It is very
36+
# similar to selection sort, except that it does not always choose
37+
# worst-case partition.

Arrays-Sorting/src/Quick_sort/quicksort.py

-37
This file was deleted.

Automation/src/geckodriver.exe

-5.62 MB
Binary file not shown.
File renamed without changes.
File renamed without changes.

PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Fixes # (issue)
1010
Please delete options that are not relevant.
1111
1212
- [ ] New Script
13-
- [ ] New Category (Is any new category being made to accomodate this script)
13+
- [ ] New Category (Is any new category being made to accommodate this script)
1414
- [ ] Bug fix (non-breaking change which fixes an issue)
1515
- [ ] New feature (non-breaking change which adds functionality)
1616
```

0 commit comments

Comments
 (0)