Skip to content

Instantly share code, notes, and snippets.

@leozc
Created February 5, 2023 04:31
Show Gist options
  • Save leozc/6cf02bd2737b031ea0e8a68d91934202 to your computer and use it in GitHub Desktop.
Save leozc/6cf02bd2737b031ea0e8a68d91934202 to your computer and use it in GitHub Desktop.
def testA ():
for i in range(3):
for p in range(i,3):
# print tuple of i and p
print((i,p))
#time to run the function
def sortA (array):
for i in range(len(array)):
#print ("i = " + str(i))
v = array[i]
#print ("v = " + str(v))
for p in range(i,len(array)):
if array[p] < v:
array[i] = array[p]
array[p] = v
v = array[i]
# print current array
#print(array)
return array
def quickSort(array):
#write quickSort without recursion
array.sort()
# generate a random array of 10 numbers
import random
#import function timing
import time
array = [random.randint(0,1000) for i in range(50000000)]
start = time.perf_counter()
print("quickSort sort: ")
quickSort(array)
end = time.perf_counter()
print("Time taken:", end - start, "seconds")
# start = time.perf_counter()
# print ("bubble sort: ")
# sortA(array)
# end = time.perf_counter()
# print("Time taken:", end - start, "seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment