예제 #1
0
def run_bubble_sort():
    ll = np.random.randint(-10, 10, 10)  #[7, 6, 5, 4, 3, 2, 1]
    bs = BubbleSort(ll)
    res = bs.sort()
    print("BubbleSort")
    print(f"before: {ll}")
    print(f"after: {res}")
    print()
예제 #2
0
    def testbubblesort(self):
        a = [random.randint(-100,100) for c in range(1000)]

        print('before sort', a)
        BubbleSort.sort(a)
        print('after sort',a)
        for i in range(len(a)-1):
            if(a[i] > a[i+1]):
                self.fail('bubble sort failed')
예제 #3
0
from bubble_sort import BubbleSort

array = [21, 4, 1, 3, 9, 20, 25, 6, 21, 1, 14]
BubbleSort(array, len(array))
print(array)
예제 #4
0
from abstract_sort import AbstractSort
from bubble_sort import BubbleSort
from quick_sort import QuickSort
from heap_sort import HeapSort
from python_sort import PythonSort

from sort_time_complexity import SortTimeComplexity

if __name__ == '__main__':
    stc = SortTimeComplexity()
    stc.run_sorter_tests(BubbleSort())
    stc.run_sorter_tests(QuickSort())
    stc.run_sorter_tests(HeapSort())
    stc.run_sorter_tests(PythonSort())
    stc.display_plot()
예제 #5
0
from bubble_sort import BubbleSort
from selection_sort import SelectionSort
from sort_strategy import SortStrategy



if __name__ == '__main__':

    # the list to sort
    my_list = [1,2,3,4,5,6,7]

    # bubbke sort algo
    b = BubbleSort()

    # Selection sort algo
    s = SelectionSort()

    # choosing the strategy - bubble sort
    print("Bubble sort :")
    strategy = SortStrategy(b)

    sorted_list = strategy.sort(my_list)

    print("result ", sorted_list)

    # changing the strategy to Selection sort
    print("Selection sort :")
    strategy.algo = s

    sorted_list = strategy.sort(my_list)
예제 #6
0
 def get_algorytm(self):
     self.list_agloritm = [BubbleSort(), QuickSort()]
예제 #7
0
from bubble_sort import BubbleSort
from merge_sort import MergeSort

list_to_sort = [5, 4, 3, 2, 1]
# list_to_sort = [1, 2, 3, 4, 5]
sorting_algo = BubbleSort()
sorting_algo.sort(list_to_sort)

print "Sorted using bubble-sort:"
print list_to_sort

list_to_sort = [5, 3, 4, 2, 1]
sorting_algo = MergeSort()
sorting_algo.sort(list_to_sort)

print "Sorted using merge-sort:"
print list_to_sort
예제 #8
0
from bubble_sort import BubbleSort
from quicksort import QuickSort
from sort_time_complexity import SortTimeComplexity


if __name__ == '__main__':
    array = [1, 5, 63, 72, 9, 34]
    bubble_sorts = BubbleSort()
    bubble_sorts.get_data(array)
    print(bubble_sorts.sort(array))
    quick_sort = QuickSort()
    # quick_sort.get_data()
    sort_machine = SortTimeComplexity()
    print(sort_machine.measure_time(bubble_sorts, array))


예제 #9
0
 def bubble_sort(array):
     start = timeit.default_timer()
     copied_array = copy.copy(array)
     BubbleSort.sort(array=copied_array)
     end = timeit.default_timer()
     return format(end - start, '.5f')
예제 #10
0
class TestBubbleSort(SortTest, unittest.TestCase):
    sorter = BubbleSort()
예제 #11
0
from counting_sort import CountingSort
from radix_sort import RadixSort
from heap_sort import HeapSort
from merge_sort import MergeSort
from quick_sort import QuickSort
from bubble_sort import BubbleSort
from selection_sort import SelectionSort
from insertion_sort import InsertionSort
from time import time

import random

options = {
    1: ("Bubble Sort", BubbleSort()),
    2: ("Selection Sort", SelectionSort()),
    3: ("Insertion Sort", InsertionSort()),
    4: ("Quick Sort", QuickSort()),
    5: ("Merge Sort", MergeSort()),
    6: ("Radix Sort", RadixSort()),
    7: ("Counting Sort", CountingSort()),
    8: ("Heap Sort", HeapSort())
}
print("Sorting Options: ")
for i in options.keys():
    print("Option {} : {}".format(i, options[i][0]))
while True:
    option = int(input("Enter sorting option: "))
    sort_alg = options[option][1]
    start = time()
    arr = [random.randint(-100000, 100000) for _ in range(10)]
    print(arr)
예제 #12
0
def fn_bubble_sort(input, output, start):
    bubb_sort = BubbleSort()
    bubb_sort.bubble_sort(input)
    assert input == output
    end = time.time()
 def test_short_bubble_sort(self):
     sortedList = BubbleSort.short_bubble_sort(self.targetList)
     self.assertTrue(sortedList == self.checkList)
 def test_bubble_sort(self):
     algo = SortingTestWrapper(BubbleSort(), self.n, self.seed)
     self.assertListEqual(algo.integer_sort(), self.verification.integer_sort())