def start():
    print('Sorting...')
    global data
    if not data:
        return

    # These if else statements call the function of the selected algorithm
    if algMenu.get() == 'Quick Sort':
        quick_sort(data, draw_data, speedScale.get())
    elif algMenu.get() == 'Bubble Sort':
        bubble_sort(data, draw_data, speedScale.get())
    elif algMenu.get() == 'Insertion Sort':
        insertion_sort(data, draw_data, speedScale.get())
    elif algMenu.get() == 'Selection Sort':
        selection_sort(data, draw_data, speedScale.get())
    elif algMenu.get() == 'Merge Sort':
        merge_sort(data, 0, len(data) - 1, draw_data, speedScale.get())
    elif algMenu.get() == 'Counting Sort':
        count_sort(data, draw_data, speedScale.get())
	def test_sorting_letters(self):
		self.assertEqual(["a"],selection_sort(["a"]))
		self.assertEqual(['C','E','T','b','c','k'],selection_sort(['T','C','c','k','E','b']))
	def test_sorting_mix(self):
		self.assertEqual([-6, 5, ',', '/', '?', 'K', 'c'],selection_sort(['/',',','c',5,-6,'K','?']))
Example #4
0
    all_lists = {}
    all_lists['ALREADY_SORTED'] = [1, 2, 4, 4, 6, 6, 8, 9]
    all_lists['REVERSE_SORTED'] = [9, 8, 6, 6, 4, 4, 2, 1]
    all_lists['FEW_UNIQUE'] = [3, 6, 6, 4, 3, 3, 3, 6, 6, 4]
    all_lists['RANDOM_ORDER'] = [2, 6, 4, 8, 1, 4, 6, 9]
    all_lists['BIG_RANGE'] = [170, 45, 75, 90, 802, 2, 24, 66]
    all_lists['LONG_LIST'] = [
        2, 4, 3, 3, 6, 7, 876, 2, 4, 8, 214, 7, 2, 7, 4, 8, 2, 7, 4, 6, 83, 2,
        6, 7, 88, 75, 2, 3, 6, 789, 86, 3, 6, 6, 3, 575, 6, 87, 8, 574
    ]
    all_lists['ZEROES_IN_LIST'] = [
        9, 0, 3, 0, 54, 6, 1, 45, 1, 57, 1, 56, 8, 8, 3, 0
    ]
    all_lists['ALL_SAME_NUMBER'] = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]

    for list_name, number_list in all_lists.iteritems():
        print "\nUSING LIST \n\t%s\n\t%s" % (list_name, number_list)

        print "Insertion sorted output: \n\t", insertion_sort(number_list)
        print "Bubble sorted output: \n\t", bubble_sort(number_list)
        print "Selection sorted output: \n\t", selection_sort(number_list)
        print "Bucket sorted output (using insertion sort and %s buckets): \n\t" % (
            buckets), bucket_sort(number_list, 3)
        print "Counting sorted output: \n\t", counting_sort(number_list)
        print "Quick sorted output: \n\t", quicksort(number_list)
        print "Merge sorted output: \n\t", mergesort(number_list)
        print "Radix sorted output (using counting sort): \n\t", radix_sort(
            number_list)
        print "Heap sorted output: \n\t", heapsort(number_list)
Example #5
0
 def test_05_three_elements(self):
     v = [2, 1, 3]
     selection_sort(v)
     self.assertEqual(v, [1, 2, 3])
Example #6
0
 def test_03_one_element(self):
     v = ["a"]
     selection_sort(v)
     self.assertEqual(v, ["a"])
Example #7
0
 def test_01_zero_elements(self):
     v = []
     selection_sort(v)
     self.assertEqual(v, [])
Example #8
0
 def test_selection_sort_empty_array(self):
     self.assertEqual(selection_sort([]), [])
Example #9
0
 def test_single_input(self):
     data = rand_list(count=1)
     data_cp = data[:]
     selection_sort(data)
     self.assertEqual(data, data_cp)
Example #10
0
 def test_zero_input(self):
     data = []
     selection_sort(data)
     self.assertEqual(data, [])
Example #11
0
from comb_sort import *
from insertion_sort import *
from merge_sort import *
from selection_sort import *
from shell_sort import *

values = range(1,10)
random.shuffle(values)
values[:]

print "List to be sorted is {0}".format(values)
print "-" * 30
print "Selection Sort"
print "-" * 30
values1 = values[:]
selection_sort(values1)
print "-" * 30
print "Insertion Sort"
print "-" * 30
values2 = values[:]
insertion_sort(values2)
print "-" * 30
print "Bubble Sort"
print "-" * 30
values3 = values[:]
bubble_sort(values3)
print "-" * 30
print "Comb Sort"
print "-" * 30
values4 = values[:]
comb_sort(values4)
Example #12
0
#!/usr/bin/python3

from bubble_sort import *
from insertion_sort import *
from selection_sort import *
from qsort import *

alist = [54,26,93,17,77,31,44,55,20]
print(alist)
bubble_sort(alist)
print(alist)

alist = [54,26,93,17,77,31,44,55,20]
print(alist)
selection_sort(alist)
print(alist)

alist = [54,26,93,17,77,31,44,55,20]
print(alist)
insertion_sort(alist)
print(alist)

alist = [54,26,93,17,77,31,44,55,20]
print(alist)
qsort(alist)
print(alist)
import time
print_list(original)
print(len(original))
print()
print("Correctly sorted: ")
a = time.time()
sorted = sorted(original)
b = time.time()
print(b - a)
print_list(sorted)
print()

print("Selection sorted: ")
selection_sorted_list = list(original)
a = time.time()
selection_sort(selection_sorted_list)
b = time.time()
print(b - a)
print_list(selection_sorted_list)
test_properties(sorted, selection_sorted_list)
print()

print("Insertion sorted: ")
insertion_sorted_list = list(original)
a = time.time()
insertion_sort(insertion_sorted_list)
b = time.time()
print(b - a)
print_list(insertion_sorted_list)
test_properties(sorted, insertion_sorted_list)
print()
def test_selection_sort():
    unsorted_list = [9, 4, 5, 1, 2, 13, 28, 31]
    sorted_list = [1, 2, 4, 5, 9, 13, 28, 31]
    assert selection_sort(unsorted_list) == sorted_list
Example #15
0
 def test_double_input(self):
     data = rand_list(count=2)
     selection_sort(data)
     self.assertLessEqual(data[0], data[1])
Example #16
0
 def test_selection_sort_with_elements(self):
     self.assertEqual(selection_sort([1,5,8,3,5,9]), [1,3,5,5,8,9])
     self.assertEqual(selection_sort([9,15,1,85,74,789,1111,3,365]), [1,3,9,15,74,85,365,789,1111])
Example #17
0
 def test_array_input(self):
     data = rand_list()
     selection_sort(data)
     for i in range(1, len(data)):
         self.assertLessEqual(data[i-1], data[i])
Example #18
0
from heap_sort import *


if __name__ == "__main__":

  buckets = 3

  all_lists = {}
  all_lists['ALREADY_SORTED'] = [1, 2, 4, 4, 6, 6, 8, 9]
  all_lists['REVERSE_SORTED'] = [9, 8, 6, 6, 4, 4, 2, 1]
  all_lists['FEW_UNIQUE'] = [3, 6, 6, 4, 3, 3, 3, 6, 6, 4]
  all_lists['RANDOM_ORDER'] = [2, 6, 4, 8, 1, 4, 6, 9]
  all_lists['BIG_RANGE'] = [170, 45, 75, 90, 802, 2, 24, 66]
  all_lists['LONG_LIST'] = [2,4,3,3,6,7,876,2,4,8,214,7,2,7,4,8,2,7,4,6,83,2,6,7,88,75,2,3,6,789,86,3,6,6,3,575,6,87,8,574]
  all_lists['ZEROES_IN_LIST'] = [9,0,3,0,54,6,1,45,1,57,1,56,8,8,3,0]
  all_lists['ALL_SAME_NUMBER'] = [7,7,7,7,7,7,7,7,7,7,7]


  for list_name, number_list in all_lists.iteritems():
    print "\nUSING LIST \n\t%s\n\t%s" %(list_name, number_list)
    
    print "Insertion sorted output: \n\t", insertion_sort(number_list)
    print "Bubble sorted output: \n\t", bubble_sort(number_list)
    print "Selection sorted output: \n\t", selection_sort(number_list)
    print "Bucket sorted output (using insertion sort and %s buckets): \n\t" %(buckets), bucket_sort(number_list, 3)
    print "Counting sorted output: \n\t", counting_sort(number_list)
    print "Quick sorted output: \n\t", quicksort(number_list)
    print "Merge sorted output: \n\t", mergesort(number_list)
    print "Radix sorted output (using counting sort): \n\t", radix_sort(number_list)
    print "Heap sorted output: \n\t", heapsort(number_list)
    
Example #19
0
 def test_all_zero_input(self):
     data = [0]*100
     selection_sort(data)
     for i in range(0, 100):
         self.assertEqual(data[i], 0)
Example #20
0
 def test_02_return_none(self):
     self.assertEqual(None, selection_sort([2]))
Example #21
0
 def test_all_same_input(self):
     single_val = rand_list(count=1)[0]
     data = [single_val]*100
     selection_sort(data)
     for i in range(0, 100):
         self.assertEqual(single_val, data[i])
Example #22
0
 def test_04_two_elements(self):
     v = [2, 1]
     selection_sort(v)
     self.assertEqual(v, [1, 2])
Example #23
0
 def test_selection_sort(self):
     self.assertEqual(selection_sort([2,3,1]), [1,2,3])
     self.assertEqual(selection_sort(([3,5,6,7,2,1,0,4,8,9])), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Example #24
0
 def test_06_piccinno_list(self):
     v = [23, 34, 55, 32, 7777, 98, 3, 2, 1]
     selection_sort(v)
     vcopy = v[:]
     vcopy.sort()
     self.assertEqual(v, vcopy)
Example #25
0
File: sort.py Project: addie/python
#!/usr/bin/python3

from bubble_sort import *
from insertion_sort import *
from selection_sort import *
from qsort import *

alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
print(alist)
bubble_sort(alist)
print(alist)

alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
print(alist)
selection_sort(alist)
print(alist)

alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
print(alist)
insertion_sort(alist)
print(alist)

alist = [54, 26, 93, 17, 77, 31, 44, 55, 20]
print(alist)
qsort(alist)
print(alist)
	def test_sorting_symbols(self):
		self.assertEqual(["!"],selection_sort(["!"]))
		self.assertEqual(['*','>','?'],selection_sort(['?','*','>']))
Example #27
0
    print(array)
    quick_sort(array, 0, len(array) - 1)
    print(array)

    ## Mergesort
    print('Mergesort:')
    array = generateArray(20)
    print(array)
    array = merge_sort(array)
    print(array)

    ## Selectionsort
    print('Selectionsort:')
    array = generateArray(20)
    print(array)
    selection_sort(array)
    print(array)

    ## Heapsort
    print('Selectionsort:')
    array = generateArray(20)
    print(array)
    heap_sort(array)
    print(array)

    ## Bubblesort
    print('Selectionsort:')
    array = generateArray(20)
    print(array)
    bubble_sort(array)
    print(array)
	def test_sorting_numbers(self):
		self.assertEqual([4],selection_sort([4]))
		self.assertEqual([-7,-4,0,2,3,10,15],selection_sort([2,-4,0,10,15,-7,3]))
Example #29
0
 def test_selection_sort_single_element(self):
     self.assertEqual(selection_sort([1]), [1])
Example #30
0
import random
from insertion_sort import *
from selection_sort import *
from merge_sort import *

my_randoms = random.sample(range(1, 100000000), 1000)

print(my_randoms)

print(insertion_sort(my_randoms))
selection_sort(my_randoms)
selection_sort_2(my_randoms)
print(merge_sort(my_randoms))
Example #31
0
            n = int(input('\n\n Aperte 0 Para Voltar: '))

    elif n == 5:
        print("\n" * 130)
        print('*** Selection Sort ***\n')
        try:
            nome_arq = input('Nome do arquivo a ser Aplicado Selection Sort: ')
            nome_arq = nome_arq + '.txt'
            arquivo = open(nome_arq, 'r')
            lista = arquivo.readlines()
            x4 = 0
            while x4 != 9:
                for index in range(len(lista)):
                    lista[index] = lista[index].rstrip('\n')
                    lista[index] = int(lista[index])
                selection_sort(lista)
                n_lista = lista
                print('*** Aplicado o Selection Sort ***\n')
                print(lista)
                arquivo = open(nome_arq, "w")
                frases = list()
                for i in range(len(n_lista)):
                    frases.append(str(n_lista[i]))
                    frases.append('\n')
                arquivo.writelines(frases)
                arquivo.close()
                x4 = int(input('\n\n Aperte 9 Para Voltar: '))

        except FileNotFoundError:
            print('Arquivo não Foi encontrado ')
            print('Erros Provaveis: Nome errado')