示例#1
0
def sort():
    global data

    timer = set_sort_speed()

    if menu.get() == 'bogo_sort':
        bogo_sort(data, drawBars, timer)

    elif menu.get() == 'bubble_sort':
        bubble_sort(data, drawBars, timer)

    elif menu.get() == 'insertion_sort':
        insertion_sort(data, drawBars, timer)

    elif menu.get() == 'quick_sort':
        quick_sort(data, 0, len(data) - 1, drawBars, timer)

    elif menu.get() == 'merge_sort':
        merge_sort(data, 0, len(data) - 1, drawBars, timer)
示例#2
0
    def visualize_algorithm(self, name: str = 'insertion_sort'):
        """ Visualizes a specific algorithm """
        options = {
            'insertion_sort': insertion_sort(self.data),
            'bubble_sort': bubble_sort(self.data),
            'selection_sort': selection_sort(self.data),
            'quick_sort': quick_sort(self.data, 0,
                                     len(self.data) - 1),
            'merge_sort': merge_sort(self.data, 0, len(self.data))
        }

        algorithm = options[name]
        plt.title(name)
        self.ani = animation.FuncAnimation(self.fig,
                                           func=self._update_animation,
                                           frames=algorithm,
                                           interval=1,
                                           repeat=False)
        plt.show()
示例#3
0
 def test_none(self):
     self.assertEqual(quick_sort(None), None)
示例#4
0
 def test_sorted(self):
     to_sort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     quick_sort(to_sort)
     self.assertEqual(to_sort, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
示例#5
0
 def test_many(self):
     to_sort = [9, 4, 1, 7, 3, 0, 6, 8, 2, 5]
     quick_sort(to_sort)
     self.assertEqual(to_sort, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
示例#6
0
 def test_two(self):
     to_sort = [2, 1]
     quick_sort(to_sort)
     self.assertEqual(to_sort, [1, 2])
示例#7
0
 def test_one(self):
     self.assertEqual(quick_sort([9]), [9])
示例#8
0
 def test_wrong_type(self):
     self.assertEqual(quick_sort(238), 238)