Ejemplo n.º 1
0
def StartAlgo():
    global data
    if not data: return
    if algMenu.get() == "Quick Sort":
        quick_sort(data, 0, len(data) - 1, draw_data, speedScale.get())

    if algMenu.get() == "Bubble Sort":
        bubbleSort(data, draw_data, speedScale.get())
    elif algMenu.get() == "Merge Sort":
        merge_sort(data, draw_data, speedScale.get())
    draw_data(data, ["yellow" for x in range(len(data))])
Ejemplo n.º 2
0
def startSort():
    global arr

    if algoCombo.get() == 'Bubble Sort':
        bubbleSort(arr, displayArray, sortSpeed.get(), pauseBool)

    elif algoCombo.get() == 'Selection Sort':
        selectionSort(arr, displayArray, sortSpeed.get(), pauseBool)

    elif algoCombo.get() == 'Merge Sort':
        mergeSort(arr, displayArray, sortSpeed.get(), pauseBool, 0,
                  len(arr) - 1)

    elif algoCombo.get() == 'Quick Sort':
        quickSort(arr, displayArray, sortSpeed.get(), pauseBool, 0,
                  len(arr) - 1)
Ejemplo n.º 3
0
def StartAlgorithm():
    global data
    if algMenu.get() == "Quick sort":
        quickSort(data, 0, len(data) - 1, drawData, speedScale.get() / 1000)
    elif algMenu.get() == "Merge sort":
        mergeSort(data, 0, len(data) - 1, drawData, speedScale.get() / 1000)
    elif algMenu.get() == "Selection sort":
        selectSort(data, drawData, speedScale.get() / 1000)
    elif algMenu.get() == "Radix sort":
        radixSort(data, drawData, speedScale.get() / 1000)
    elif algMenu.get() == "Insertion sort":
        insertSort(data, drawData, speedScale.get() / 1000)
    elif algMenu.get() == "Bubble sort":
        bubbleSort(data, drawData, speedScale.get() / 1000)

    drawData(data, ["limegreen" for _ in range(len(data))])
Ejemplo n.º 4
0
    def test_sample(self):
        testList = [4, 3, 2, 1]
        expectedList = testList.copy()
        expectedList.sort()
        actualList = bt.bubbleSort(testList)

        self.assertEqual(actualList, expectedList)
Ejemplo n.º 5
0
    def test_empty(self):
        testList = []
        expectedList = testList.copy()
        expectedList.sort()
        actualList = bt.bubbleSort(testList)

        self.assertEqual(actualList, expectedList)
Ejemplo n.º 6
0
    def test_random(self):
        testList = [random.randint(0, 20) for i in range(4)]
        expectedList = testList.copy()
        expectedList.sort()
        actualList = bt.bubbleSort(testList)

        self.assertEqual(actualList, expectedList)
Ejemplo n.º 7
0
    def test_negatives(self):
        testList = [-4, -3, -2, -1]
        expectedList = testList.copy()
        expectedList.sort()
        actualList = bt.bubbleSort(testList)

        self.assertEqual(actualList, expectedList)
Ejemplo n.º 8
0
    def test_presorted(self):
        testList = [1, 2, 3, 4]
        expectedList = testList.copy()
        expectedList.sort()
        actualList = bt.bubbleSort(testList)

        self.assertEqual(actualList, expectedList)
Ejemplo n.º 9
0
#This file is just to compile all the feature branches

from bubblesort import bubbleSort
from mergeSort import mergeSort
from quicksort import quickSort

testBubble = [3, 10, 40, 20, 30, 4, 1]
testMerge = [100, 5, 68, 3, 1, 10]
testQuick = [4, 15, 23, 1, 11, 22]

bubbleSort(testBubble)
print("Here is the the sorted array using bubble sort")
print(testBubble)
mergeSort(testMerge)
print("Here is the sorted array using Merge sort")
print(testMerge)
quickSort(testQuick, 0, len(testQuick) - 1)
print("Here is the sorted array using quick sort")
print(testQuick)
Ejemplo n.º 10
0
 def test_mix_sorted(self): 
     """Can bubble sort handle an array with number in mixed order?"""
     result = bubbleSort([3,2,1,4,5]);
     self.assertEqual(result,[1,2,3,4,5]);
Ejemplo n.º 11
0
import bubblesort

list1 = [67, 45, 2, 13, 1, 998]
list2 = [89, 23, 33, 45, 10, 12, 45, 45, 45]

print(bubblesort.bubbleSort(list1))
print(bubblesort.bubbleSort(list2))
def sort_Bubble(order, key):
    result = bubbleSort(supermarket_obj_list, order, key)
    #return a sorted list of objects
    return result
Ejemplo n.º 13
0
def main():
    # List to sort
    num_bars = DATA_SIZE[0] // (BAR_WIDTH + 1)
    arr = [DATA_SIZE[1] // num_bars * i for i in range(1, num_bars)]

    # Window layout
    graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE, background_color='#F5F6F4')
    layout = [[
        sg.Text('Visualization',
                size=(30, 1),
                font=("Helvetica", 25),
                background_color='#8F90A0',
                text_color='#FFFFFF')
    ], [graph],
              [
                  sg.Button('Select sorting method',
                            button_color=['#FFFFFF', '#35343B'],
                            font=("Helvetica", 12)),
                  sg.Button('Generate new array',
                            button_color=['#FFFFFF', '#35343B'],
                            font=("Helvetica", 12))
              ]]

    window = sg.Window('Algorithm Visualizer', layout)
    window.Finalize()

    draw_bars(graph, arr)

    while True:
        event, values = window.read()
        if event in (None, 'Exit'):
            break

        if event == 'Generate new array':
            graph.Erase()
            random.shuffle(arr)
            draw_bars(graph, arr)

        if event == 'Select sorting method':
            l2 = [[
                sg.T('Choose sorting method',
                     font=("Helvetica", 12),
                     background_color='#8F90A0',
                     text_color='#FFFFFF')
            ], [
                sg.Listbox(['Bubble', 'Insertion', 'Selection'], size=(16, 3))
            ], [sg.Ok()]]
            w2 = sg.Window('Choose sorting method', l2)
            button, values = w2()
            w2.close()
            try:
                if values[0][0] == 'Bubble':
                    sort = bubblesort.bubbleSort(arr)
                    sortmethod = 'Bubble'

                elif values[0][0] == 'Insertion':
                    sort = insertionsort.insertionSort(arr)
                    sortmethod = 'Insertion'

                else:
                    sort = selectionsort.selectionSort(arr)
                    sortmethod = 'Selection'
            except:
                sg.Popup('None selected.',
                         font=("Helvetica", 12),
                         background_color='#8F90A0',
                         text_color='#FFFFFF')
                continue

            timeout = 10

            for partially_sorted_list in sort:
                event, values = window.read(timeout=timeout)
                if event is None:
                    break
                graph.Erase()
                draw_bars(graph, partially_sorted_list)
                timeout = int(10)
            sg.Popup(f'{sortmethod} sort done.',
                     font=("Helvetica", 12),
                     background_color='#8F90A0',
                     text_color='#FFFFFF')
import bubblesort as st

testlist = [5, 4, 3, 6, 10, 1, 2, 3]

print(st.bubbleSort(testlist))
Ejemplo n.º 15
0
import time
from generator import generator
from bubblesort import bubbleSort
from mergesort import merge_sort
from quicksort import quickSort
from selectionsort import selectionSort

arr = []

generator()

# for line in fp:
# arr.append(int(line.strip()))

start = time.process_time()
bubbleSort(arr)
end = time.process_time()
elapsed = (end - start) * (10**6)
print("Time for Bubblesort:")
print("%.3f" % (elapsed))

start = time.process_time()
merge_sort(arr)
end = time.process_time()
elapsed = (end - start) * (10**6)
print("Time for Mergesort:")
print("%.3f" % (elapsed))

start = time.process_time()
quickSort(arr)
end = time.process_time()
Ejemplo n.º 16
0
def bubbleTest ():
	bubble_list = [3,5,2,7,1]
	print "Before Sort:\t", bubble_list
	for i in range (1,len(bubble_list)):
		bubbleSort(bubble_list)
	print "After Sort: \t", bubble_list
Ejemplo n.º 17
0
import bubblesort, time

arr = bubblesort.arrMaker(1, 25000, 100)
print("before sort(start and end 5 numbers):", arr[0:5], "...", arr[-5:])
print("------bubbleSorting------")
start = time.time()
arr = bubblesort.bubbleSort(arr)
print("-----completed  sort-----")
print("after sort(start and end 5 numbers):", arr[0:5], "...", arr[-5:])
print("time used to sort:", time.time() - start)
Ejemplo n.º 18
0
 def test_reverse_sorted(self):
     """Can bubble sort correctly sort a reverse sorted array?""" 
     result = bubbleSort([150, 83, 23, 12, 10, 6.2, 5]);
     self.assertEqual(result,[5,6.2,10,12,23,83,150]);
def test_bubbleSort():
    mylist = [12, 34, 67, 45, 23, 36, 5, 17, 40, 10]
    sorted_list = bubbleSort(mylist)
    assert sorted_list == [5, 10, 12, 17, 23, 34, 36, 40, 45, 67]
Ejemplo n.º 20
0
def bubbleTest():
    bubble_list = [3, 5, 2, 7, 1]
    print "Before Sort:\t", bubble_list
    for i in range(1, len(bubble_list)):
        bubbleSort(bubble_list)
    print "After Sort: \t", bubble_list
Ejemplo n.º 21
0
start_time = time.time()
import mergesort
mergesort.mergeSort(alist)
print('2 . Sorted numbers by a Mergesort are :  ')
print(alist)
r2=time.time() - start_time
print("--- %s seconds for Mergesort ---" % (r2))           #getting the running time
height.append(r2)                                          #to get the height for the graph


print('\v')

import time
start_time = time.time()
import bubblesort
bubblesort.bubbleSort(alist)
print('3 . Sorted numbers by a Bubblesort are : ')
print(alist)
r3=time.time() - start_time
print("--- %s seconds for Bubblesort ---" % (r3))                       #getting the running time
height.append(r3)                                                       #to get the height for the graph


print('\v')

import time
start_time = time.time()
import insertionsort
insertionsort.insertionSort(alist)
print('4 . Sorted numbers by a Insertionsort are : ')
print(alist)
Ejemplo n.º 22
0
 def test_pre_sorted(self): 
     """Will bubble sort accept a pre-sorted array without failure?"""
     result = bubbleSort([5,10,15,20,25,30]);
     self.assertEqual(result, [5,10,15,20,25,30]);