Esempio n. 1
0
def sort(a, l=None, r=None):
    l = l or 0
    r = r or len(a)
    if r - l > 1:
        if r - l < 5:
            # if there are less than 5 elements
            # use bubble sort
            bubblesort.sort(a, l, r)
        else:
            p = partition(a, l, r)
            sort(a, l, p)
            sort(a, p + 1, r)
Esempio n. 2
0
import bubblesort

print bubblesort.sort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1])
print bubblesort.sort([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print bubblesort.sort([6, 7, 8, 9, 10, 1, 2, 3, 4, 5])

print bubblesort.sort(12323123)
print bubblesort.sort("thisshouldn'twork")  # need to implement error checking
Esempio n. 3
0
 def test_bubblesort(self):
   retlist = bubblesort.sort(self.unsorted)
   self.assertEqual(retlist, self.expected)
Esempio n. 4
0
def do_bubblesort(strings):
    return bubblesort.sort(strings)
Esempio n. 5
0
import bubblesort, linearsort
from msvcrt import getch
while True:
    print("Enter the first letter of the sorting algorithm you wish to test, or q to quit:")
    if getch() == b'b':
        bubblesort.sort()
    elif getch() == b'l':
        linearsort.sort()
    elif getch() == b'q':
        break
    else:
        continue
Esempio n. 6
0
 def test_bubblesort(self):
     retlist = bubblesort.sort(self.unsorted)
     self.assertEqual(retlist, self.expected)
Esempio n. 7
0
import csv
import time

import bubblesort
import quicksort
import mergesort
import selectionsort

debug = False

data = []
with open('test-data/way-round-1E3.csv', 'r') as csvfile:
	spamreader = csv.reader(csvfile)
	data = [[int(number) for number in row] for row in spamreader]

list = data[0]
list_sorted = data[1]

if debug:
	print('Pre', list)
	print('Sorted', list_sorted)

start = time.time()
list = bubblesort.sort(list, debug)
end = time.time()

if debug:
	print('Post', list)

print('Correct:', list == list_sorted)
print('Performance:', (end - start) * 1000, 'ms')
Esempio n. 8
0
simpleselectsortlist = list.copy()
bubblesortlist = list.copy()
mergesortlist = list.copy()

heapsort.sort(list)
print(list)

list = qsortlist
qsort.sort(list)
print(list)

list = simpleselectsortlist
simpleselectsort.sort(list)
print(list)

bubblesort.sort(bubblesortlist)
print(bubblesortlist)

mergesort.sort(mergesortlist)
print(mergesortlist)

list = []
for i in range(1, 1000 * 10):
    list.append(i)

random_list(list)

print(list[0:29])

list2 = list.copy()
list3 = list.copy()
Esempio n. 9
0
 def test_normal(self):
   data = [ random.randint(0,100) for _ in range(0,100) ] 
   sorted_data = copy.copy(data)
   sorted_data.sort()
   bubblesort.sort(data)
   self.assertEqual(data, sorted_data)
Esempio n. 10
0
def do_bubblesort(strings):
    return bubblesort.sort(strings)
Esempio n. 11
0
import bubblesort

print bubblesort.sort([10,9,8,7,6,5,4,3,2,1])
print bubblesort.sort([1,2,3,4,5,6,7,8,9,10])
print bubblesort.sort([6,7,8,9,10,1,2,3,4,5])

print bubblesort.sort(12323123)
print bubblesort.sort("thisshouldn'twork") # need to implement error checking