Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, time, sys
- random_numbers = []
- def bubble_sort(lst):
- for i in range(0, len(lst)-1):
- for j in range(0, len(lst)-1):
- if lst[j] > lst[j + 1]:
- temp = lst[j]
- lst[j] = lst[j + 1]
- lst[j + 1] = temp
- return(lst)
- def insertion_sort(lst):
- length = range(1, len(lst))
- for i in length:
- value = lst[i]
- while lst[i-1] > value and i > 0:
- lst[i], lst[i - 1] = lst[i - 1], lst[i]
- i = i - 1
- return(lst)
- def quick_sort(lst):
- length = len(lst)
- if length <= 1:
- return lst
- else:
- pivot = lst.pop()
- greater = []
- lower = []
- for i in lst:
- if i > pivot:
- greater.append(i)
- else:
- lower.append(i)
- return quick_sort(lower) + [pivot] + quick_sort(greater)
- start1 = time.time()
- (bubble_sort(random_numbers))
- end1 = time.time()
- print("Bubble Sort Time:", end1-start1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement