예제 #1
0
from vector.ArrayVector import VectorArray

unsorted_list = [12340981234,2349823,1209475,123,234,34,45,567,67,6,2,5,8,3,1,2,7,9,10,200,13,245,9823,-1]

tests = VectorArray()

for i in range(3):
    tests.append(VectorArray())
    tests[i].build_from_list(unsorted_list)

print("Numbers before sorting")
for item in tests[0]:
    print(item, end=", ")
print("")
tests[0].insertion_sort()
print("After insertion sort")
for item in tests[0]:
    print(item, end=", ")
print("")

tests[1].merge_sort()
print("After merge sort")
for item in tests[1]:
    print(item, end=", ")
print("")

tests[2].radix_sort()
print("After radix sort")
for item in tests[0]:
    print(item, end=", ")
print("")
예제 #2
0
from vector.ArrayVector import VectorArray

unsorted_list = [
    12340981234, 2349823, 1209475, 123, 234, 34, 45, 567, 67, 6, 2, 5, 8, 3, 1,
    2, 7, 9, 10, 200, 13, 245, 9823, -1
]

tests = VectorArray()

for i in range(3):
    tests.append(VectorArray())
    tests[i].build_from_list(unsorted_list)

print("Numbers before sorting")
for item in tests[0]:
    print(item, end=", ")
print("")
tests[0].insertion_sort()
print("After insertion sort")
for item in tests[0]:
    print(item, end=", ")
print("")

tests[1].merge_sort()
print("After merge sort")
for item in tests[1]:
    print(item, end=", ")
print("")

tests[2].radix_sort()
print("After radix sort")
예제 #3
0
from vector.ArrayVector import VectorArray
import ctypes, random, time

input_sizes = [10000, 20000, 40000, 80000, 100000]
sort_types = ["merge sort", "radix sort"]

# Our not insertion sorts run first because they're quick
for i in range(2):
    for size in input_sizes:
        random_list = VectorArray(cap=size)
        for j in range(size):
            random_list.append(random.randrange(0, size, 1))
        start_time = time.time()
        if i == 0:
            random_list.merge_sort()
        else:
            random_list.radix_sort()
        end_time = time.time()
        run_time = end_time - start_time
        print("Time to sort " + str(size) + " items with " + sort_types[i] +
              ": " + str(run_time))

# Insertion sort runs on its own because it's terribly slow and I had to split execution up
for size in input_sizes:
    random_list = VectorArray(cap=size)
    for j in range(size):
        random_list.append(random.randrange(0, size, 1))
    start_time = time.time()
    random_list.insertion_sort()
    end_time = time.time()
    run_time = end_time - start_time
예제 #4
0
from vector.ArrayVector import VectorArray
import ctypes, random, time

input_sizes = [10000, 20000, 40000, 80000, 100000]
sort_types = ["merge sort", "radix sort"]

# Our not insertion sorts run first because they're quick
for i in range(2):
    for size in input_sizes:
        random_list = VectorArray(cap=size)
        for j in range(size):
            random_list.append(random.randrange(0, size, 1))
        start_time = time.time()
        if i == 0:
            random_list.merge_sort()
        else:
            random_list.radix_sort()
        end_time = time.time()
        run_time = end_time - start_time
        print("Time to sort " + str(size) + " items with " + sort_types[i] + ": " + str(run_time))

# Insertion sort runs on its own because it's terribly slow and I had to split execution up
for size in input_sizes:
    random_list = VectorArray(cap=size)
    for j in range(size):
        random_list.append(random.randrange(0, size, 1))
    start_time = time.time()
    random_list.insertion_sort()
    end_time = time.time()
    run_time = end_time - start_time
    print("Time to sort " + str(size) + " items with insertion sort: " + str(run_time))