import insertion_sort import merge_sort import shell_sort import selection_sort list_bs = [2, 4, 7, 9, 11, 44, 35] print('Data Sebelum : ', list_bs) print('Bubble Sort : ') bubble_sort.bubblesort(list_bs) print('=====================================================') list_is = [76, 33, 46, 64, 20] print('Data Sebelum : ', list_is) print('Insertion Sort : ') insertion_sort.insertionsort(list_is) print('=====================================================') list_ms = [2, 5, 60, 43] print('Data Sebelum : ', list_ms) print('Merge Sort : ') merge_sort.mergesort(list_ms) print('=====================================================') list_ss = [11, 57, 33, 44, 55, 81] print('Data Sebelum : ', list_ss) print('Selection Sort : ') selection_sort.selectionsort(list_ss)
iter_num = int(input("Enter number of iterations: ")) length = 3 input_sizes = [] insertion = [] selection = [] bubble = [] heap = [] array = [] merge = [] quick = [] quickmed = [] for i in range(iter_num): for a in range(length): arr = rnd.randint(-length * 10, length * 10) array.append(arr) ar, insertion_time = insertionsort(array) insertion.append(insertion_time) ar, selection_time = selectionsort(array) selection.append(selection_time) ar, bubble_time = bubblesort(array) bubble.append(bubble_time) ar, heap_time = insertionsort(array) heap.append(heap_time) ar, merge_time = mergesort(array) merge.append(merge_time) ar, quick_time = quicksort(array, 0, len(array) - 1) quick.append(quick_time) ar, quickmed_time = quicksortmed(array, 0, len(array) - 1) quickmed.append(quickmed_time) input_sizes.append(length) length = length * 3
f.write("1111\n") datalist1 = [] datalist2 = [] datalist3 = [] print(file) f = open(file, "r") f_line = f.readlines() for line in f_line: datalist1.append(line.strip()) datalist2.append(line.strip()) datalist3.append(line.strip()) datalist1 = list(map(int, datalist1)) datalist2 = list(map(int, datalist2)) datalist3 = list(map(int, datalist3)) start_time1 = time.time() merge_sort.merge_sort(datalist1) spent_time1 = time.time() - start_time1 print("The runtime cost of merge sort is", spent_time1) start_time2 = time.time() bubble_sort.bubble_sort(datalist2) spent_time2 = time.time() - start_time2 print("The runtime cost of bubble sort is", spent_time2) start_time3 = time.time() insertion_sort.insertionsort(datalist3) spent_time3 = time.time() - start_time3 print("The runtime cost of insertion sort is", spent_time3)
print('5. Quick Sort') print('6. Heap Sort') ch = int(input("Enter your choice: ")) y = np.random.randint(1, n + 1, n) fig, axes = plt.subplots() if ch == 1: title = 'BUBBLE SORT O(n**2)' generator = bubblesort(y) elif ch == 2: title = 'SELECTION SORT O(n**2)' generator = selectionsort(y) elif ch == 3: title = 'INSERTION SORT O(n**2)' generator = insertionsort(y) elif ch == 4: title = 'MERGE SORT O(n*log(n))' generator = mergesort(y, 0, n - 1) elif ch == 5: title = 'QUICK SORT O(n*log(n))' generator = quicksort(y, 0, n - 1) elif ch == 6: title = 'HEAP SORT O(n**log(n))' generator = heapsort(y, n) mycmap = cm.get_cmap('rainbow') my_norm = Normalize(vmin=0, vmax=100) barr = axes.bar(np.arange(1, n + 1),