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) print('=====================================================') list_shs = [12, 34, 54, 2, 3] n = len(list_shs) print("Data Sebelum : ") for i in range(n): print(list_shs[i]), shell_sort.shellSort(list_shs) print("\nShell Sort : ") for i in range(n): print(list_shs[i])
print('2. Selection Sort') print('3. Insertion Sort') print('4. Merge Sort') 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')
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 print("Input sizes: ", input_sizes)
# this is the main_program for importing sorts algorithm # import all algorithm sort as module import selection_sort import merge_sort import insertion_sort import counting_sort import bubble_sort # how to use selection sort # give nlist as an input list to sort nlist = [9, 12, 98, 17, 22, 3] selection_sort.selectionsort(nlist) print(nlist) # how to use merge sort # give nlist as an input list to sort nlist = [23, 88, 98, 99, 12, 18, 71, 4] merge_sort.mergesort(nlist) print(nlist) # how to use insertion sort # give 'data' as an input list to sort data = [3, 8, 12, 98, 92, 64, 23, 10] insertion_sort.insertion(data) print(data) # how to use counting sort # give nlist as an input list to sort # and an integer to set it as maximum value nlist = [1, 4, 1, 2, 2, 5, 2] max_value = 7