def testbubblesort(self): a = [random.randint(-100,100) for c in range(1000)] print('before sort', a) BubbleSort.sort(a) print('after sort',a) for i in range(len(a)-1): if(a[i] > a[i+1]): self.fail('bubble sort failed')
def run_bubble_sort(): ll = np.random.randint(-10, 10, 10) #[7, 6, 5, 4, 3, 2, 1] bs = BubbleSort(ll) res = bs.sort() print("BubbleSort") print(f"before: {ll}") print(f"after: {res}") print()
from bubble_sort import BubbleSort from merge_sort import MergeSort list_to_sort = [5, 4, 3, 2, 1] # list_to_sort = [1, 2, 3, 4, 5] sorting_algo = BubbleSort() sorting_algo.sort(list_to_sort) print "Sorted using bubble-sort:" print list_to_sort list_to_sort = [5, 3, 4, 2, 1] sorting_algo = MergeSort() sorting_algo.sort(list_to_sort) print "Sorted using merge-sort:" print list_to_sort
from bubble_sort import BubbleSort from quicksort import QuickSort from sort_time_complexity import SortTimeComplexity if __name__ == '__main__': array = [1, 5, 63, 72, 9, 34] bubble_sorts = BubbleSort() bubble_sorts.get_data(array) print(bubble_sorts.sort(array)) quick_sort = QuickSort() # quick_sort.get_data() sort_machine = SortTimeComplexity() print(sort_machine.measure_time(bubble_sorts, array))
def bubble_sort(array): start = timeit.default_timer() copied_array = copy.copy(array) BubbleSort.sort(array=copied_array) end = timeit.default_timer() return format(end - start, '.5f')