-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_and_search.py
More file actions
53 lines (36 loc) · 1.09 KB
/
sort_and_search.py
File metadata and controls
53 lines (36 loc) · 1.09 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
#### python binary search implement
import random
from time import time
def merge_sort(unsorted_list):
pass
#divide and conquerer
def quick_sort(unsorted_list):
quick_sort_partition(unsorted_list, 0, len(unsorted_list) -1)
def quick_sort_partition(myList, start, end):
if start < end:
pass
def partition(myList, start, end):
pivot_val = myList[start]
# slow - O ( n^2 )
def bubble_sort(myList):
sorted = False
while not sorted:
sorted = True
for j in range(len(myList)-1):
#flip the number to the end
if myList[j] > myList[j +1]:
sorted = False
temp = myList[j+1]
myList[j+1] = myList[j]
myList[j] = temp
return myList
if __name__ == "__main__":
#generate list
unsorted_list = random.sample(range(1,1000), 100)
print(unsorted_list)
print("------------------")
#bubble sort
t = time()
sorted_list = bubble_sort(unsorted_list)
print("Bubble sort: {}".format( time() - t))
print(sorted_list)