def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) merge = MergeSort() merge.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) selection = SelectionSort() selection.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) count = CountSort() count.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) shell = ShellSort() shell.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) quick = QuickSort() quick.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) bubble = BubbleSort() bubble.sort(mylist) print(mylist)
def main(): util = ArrayUtil() mylist = util.generateRandomArray(10) print(mylist) insertion = InsertionSort() insertion.sort(mylist) print(mylist)
def main(): util = ArrayUtil() list = util.generateRandomArray(10) util.printList(list) r = randint(0, 9) print(r, ": ", list[r]) list.pop(r) util.printList(list) missing = findMissing(list) print("missing1: ", missing) missing = findMissing2(list) print("missing2: ", missing) missing = findMissing3(list) print("missing3: ", missing)
import time from util.ArrayUtil import ArrayUtil def linear_sum(S, n): if (n == 0): return 0 return linear_sum(S, n-1) + S[n-1] def binary_sum(S, start, stop): if (start >= stop): return 0 elif (start==stop-1): return S[start] else: mid = (start + stop) // 2 return binary_sum(S, start, mid) + binary_sum(S, mid, stop) S = ArrayUtil.generateRandomArray(990) start_time = time.time() sum = linear_sum(S, len(S)) print(sum) print("--- %s seconds ---" % (time.time() - start_time)) start_time = time.time() sum = binary_sum(S, 0, len(S)) print(sum) print("--- %s seconds ---" % (time.time() - start_time))