-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomQuickSort.py
31 lines (21 loc) · 950 Bytes
/
RandomQuickSort.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
import random
arr = [random.randrange(100) for i in range(10)] # Creat random list
def checkSort(array) -> bool: # Function for check sort status
for i in range(len(array) - 1):
if array[i] > array[i + 1]: # If all elements less than the following then sorted is True
return True
return False
def randomQuick(array): # Random quick sort function
done = True
while done:
for i in range(len(array) - 1):
point = random.randrange(len(array) - 1) # Creat random point from start
if array[point] > array[point + 1]:
sortPoint = array[point]
if array[point + 1] < sortPoint:
array[point], array[point + 1] = array[point + 1], array[point] # Replace elements
break
done = checkSort(array) # Check sort status
return array
print(arr)
print(randomQuick(arr))