Esempio n. 1
0
def StartAlgorithm():
    global data

    scale = speedScale.get()
    if not data: return

    if algMenu.get() == 'Quick Sort':
        quick_sort(
            data,
            0,
            len(data) - 1,
            drawData,
            scale,
        )

    elif algMenu.get() == 'Bubble Sort':
        bubbleSort(data, drawData, scale)
    elif algMenu.get() == 'Selection Sort':
        selectionSort(data, drawData, scale)
    elif algMenu.get() == 'Merge Sort':
        mergeSort(data, drawData, scale)
    elif algMenu.get() == 'Insertion Sort':
        insertionSort(data, drawData, scale)

    drawData(data, ['green' for x in range(len(data))])
Esempio n. 2
0
def main():
	toSort = list(range(0, 21))
	fyShuffle(toSort)
	bubbleSort(toSort)
	fyShuffle(toSort)
	insertionSort(toSort)
	fyShuffle(toSort)
	mergeSort(toSort)
	fyShuffle(toSort)
	quickSort(toSort)
	fyShuffle(toSort)
	selectionSort(toSort)

	toSearch = [-16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
	for i in range (0, len(toSearch)):
		binarySearch(toSearch, toSearch[i] - 1)
		binarySearch(toSearch, toSearch[i])
		binarySearch(toSearch, toSearch[i] + 1)
	
	for i in range (0, len(toSearch)):
		interpolationSearch(toSearch, toSearch[i] - 1)
		interpolationSearch(toSearch, toSearch[i])
		interpolationSearch(toSearch, toSearch[i] + 1)

	toSearch = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10]
	for i in range (0, len(toSearch)):
		binarySearch(toSearch, toSearch[i] - 1)
		binarySearch(toSearch, toSearch[i])
	
	for i in range (0, len(toSearch)):
		interpolationSearch(toSearch, toSearch[i] - 1)
		interpolationSearch(toSearch, toSearch[i])
Esempio n. 3
0
def startAlgorithm():
    global data
    #check which algorithm is selected
    if algoMenu.get() == 'Bubble Sort':
        bubbleSort(data, draw, speed.get())
    elif algoMenu.get() == 'Merge Sort':
        mergeSort(data, draw, speed.get())
    elif algoMenu.get() == 'Selection Sort':
        selectionSort(data, draw, speed.get())
    elif algoMenu.get() == 'Insertion Sort':
        insertionSort(data, draw, speed.get())
    elif algoMenu.get() == 'Quick Sort':
        quick_sort(data, 0, len(data) - 1, draw, speed.get())
        draw(data, ['green' for x in range(len(data))])
Esempio n. 4
0
def runTimeSelect(aList, n, selectTimes):
    start = time.time()
    selectionL = ss.selectionSort(aList)
    end = time.time()
    selectTimes.append(((end - start), n))
    print("Selection Sort: {:.10f} seconds\n".format(end - start))
    return selectTimes
Esempio n. 5
0
def startAlgorithm():
    global data
    if not data: return

    if(algMenu.get() == 'Bubble Sort'):
        bubbleSort(data, drawData, speedScale.get())
    elif(algMenu.get() == 'Quick Sort'):
        quickSort(data, drawData, speedScale.get())
        drawData(data, ['green' for x in range(len(data))])
    elif(algMenu.get() == 'Insertion Sort'):
        insertionSort(data, drawData, speedScale.get())
    elif(algMenu.get() == 'Selection Sort'):
        selectionSort(data, drawData, speedScale.get())
    elif (algMenu.get() == 'Heap Sort'):
        heapSort(data, drawData, speedScale.get())
    elif (algMenu.get() == 'Merge Sort'):
        mergeSort(data, drawData, speedScale.get())
        drawData(data, ['green' for x in range(len(data))])
Esempio n. 6
0
def quickSort(arr):
    size = len(arr)

    if size <= MIN_SIZE:
        return selectionSort(arr)

    x = get_partition(arr)
    l_arr, r_arr = split_array(arr, x)

    l_sort_arr = quickSort(l_arr)
    r_sort_arr = quickSort(r_arr)

    return l_sort_arr + r_sort_arr
Esempio n. 7
0
def sortAlgo():
    global boo
    global array
    global barRec
    global epochs

    epochs = [0]
    boo = True

    try:
        size = int(sizeEntry.get())
    except:
        size = 15
    if size < 0:
        size = 1

    #change the value of the speed selected
    s = 1001 - speed.get()

    #decide the algo
    if algDropDown.get() == "Merge Sort":
        algo = mergeSort(array, 0, size - 1)
    elif algDropDown.get() == "Bubble Sort":
        algo = bubbleSort(array)
    elif algDropDown.get() == "Quick Sort":
        algo = quickSort(array, 0, size - 1)
    elif algDropDown.get() == "Insertion Sort":
        algo = insertionSort(array)
    elif algDropDown.get() == "Selection Sort":
        algo = selectionSort(array)
    elif algDropDown.get() == "Heap Sort":
        algo = heapSort(array)
    elif algDropDown.get() == "Radix Sort":
        algo = radixSort(array)

    #start animation
    anima = anim.FuncAnimation(fig,
                               func=updatePlot,
                               fargs=(barRec, epochs),
                               frames=algo,
                               interval=s,
                               repeat=False,
                               blit=False)
    anima._start()
Esempio n. 8
0
 def testSelectionSort(self):
     A = [5, 1, 3, 0, 10]
     selectionSort.selectionSort(A)
     B = [0, 1, 3, 5, 10]
     if (A != B):
         self.fail("selectionSort method fails.")
from selectionSort import selectionSort

testArr = [5, -7, 8, 99, -7, 19, 8, 22, 999, -70, 0]

selSort = selectionSort()
print selSort.sort(testArr)
print selSort.sort(testArr) == [-70, -7, -7, 0, 5, 8, 8, 19, 22, 99, 999]
 def sortMethod(self, arr):
     selectionSort(arr)
from selectionSort import selectionSort
input = raw_input("please input a list of numbers:  ")
numbers = map(int, input.split(","))
selectionSort(numbers)
for i in range(0,len(numbers)):
	print numbers[i]
Esempio n. 12
0
from selectionSort import selectionSort

input = raw_input("please input a list of numbers:  ")
numbers = map(int, input.split(","))
selectionSort(numbers)
for i in range(0, len(numbers)):
    print numbers[i]
Esempio n. 13
0
quickSort.quick_sort(data5,0,len(data5))
e5 = time.clock()
print 'quick_sort:', e5-s5

s6 = time.clock()
quickSort.qSort(data6)
e6 = time.clock()
print 'qSort:', e6-s6

s3 = time.clock()
insertionSort.insertionSort(data3)
e3 = time.clock()
print 'insertionSort:', e3-s3

s8 = time.clock()
insertionSort.insertSort(data8, 0, len(data8))
e8 = time.clock()
print 'insertSort:', e8-s8


s4 = time.clock()
selectionSort.selectionSort(data4)
e4 = time.clock()
print 'selectionSort:', e4-s4

s2 = time.clock()
bubbleSort.bubble_sort(data2, 0, len(data2))
e2 = time.clock()
print 'bubble_sort:', e2-s2

Esempio n. 14
0
import bubbleSort
import selectionSort
import insertSort
import shellSort
import mergeSort

list = [2, 5, 60, 43, 27, 10, 89, 17]
print('\nData yang akan di sort :\n', list)
print('\nBubble Sort :\n')
bubbleSort.bubbleSort(list)
print("\n==================================================\n")

print('\nSelection Sort :\n')
selectionSort.selectionSort(list)
print("\n==================================================\n")

print('\nInsert Sort :\n')
insertSort.insertionSort(list)
print("\n==================================================\n")

sublist = len(list)
shellSort.shellSort(list)
print("\nShell Sort :\n")
for i in range(sublist):
    print(list[i])
print("\n==================================================\n")

print('\nMerge Sort :\n')
mergeSort.mergeSort(list)
print("\n==================================================\n")
Esempio n. 15
0
 def test_case1(self):
     test1 = [4, 3, 2, 1, 0]
     output = selectionSort(test1)
     expected = [0, 1, 2, 3, 4]
     self.assertEqual(output, expected)
Esempio n. 16
0
	def test_case_3(self):
		self.assertEqual(selectionSort([]), [])
Esempio n. 17
0
	def test_case_4(self):
		self.assertEqual(selectionSort([-5, 3, 4, 1, 2]), [-5,1,2,3,4])
Esempio n. 18
0
	def test_case_2(self):
		self.assertEqual(selectionSort([5, 3, 4, 1, 2]), [1,2,3,4,5])
Esempio n. 19
0
	def test_case_1(self):
		self.assertEqual(selectionSort([8, 1, 2, 3, 4, 5, 6, 7]), [1,2,3,4,5,6,7,8])