コード例 #1
0
 def bubbleClick():  #button that is used to start a bubblesort
     stopClick()
     actionText.set("Bubble Sorting...")
     if not isinstance(
             self.currentSort, BubbleSort
     ):  #if the current sort is not a bubble sort then create a new bubblesort object
         self.currentSort = BubbleSort(self,
                                       speedSlider.get() / float(1000),
                                       self.list, self.myPlot)
         self.timeComplexity.set(self.currentSort.getTimeComplexity())
     self.currentSort.timeStep = speedSlider.get() / float(
         1000
     )  #set the current sort timestep. Semi-redundant but is useful if the user wants to change the speed of the current sort.
     if not correctnessCheck(
             self.list
     ):  #if it fails the correctnessCheck... (is useful so the user won't try sorting a sorted list. Could be removed if it is something that I would like the user to be able to do i.e. best case scenario sorts)
         self.currentSort.kill = False
         self.timeToSort.set('Time to sort: ...')
         self.start = time.time()
         self.currentSort.bubbleSort()
         self.stop = time.time()
         self.timeToSort.set(
             'Time to sort: {:.3f} seconds'.format(self.stop -
                                                   self.start))
     checkClick()
     actionText.set("Idle...")
コード例 #2
0
 def checkClick(
 ):  #button that is used to check if the current list is sorted correctly
     actionText.set("Checking Correctness...")
     if correctnessCheck(
             self.list
     ):  #if the correctnessCheck definition returns true set the correct text variable to sorted correctly
         correctText.set("Sorted Correctly!")
     else:  #else if the correctnessCheck definition returns false, set the correct text variable to not sorted correctly
         correctText.set("Not Sorted Correctly :(")
     actionText.set("Idle...")
コード例 #3
0
 def heapClick():  #button that is used to start a radix sort
     stopClick()
     actionText.set("Heap Sorting...")
     if not isinstance(self.currentSort, HeapSort):
         self.currentSort = HeapSort(self,
                                     speedSlider.get() / float(1000),
                                     self.list, self.myPlot)
         self.timeComplexity.set(self.currentSort.getTimeComplexity())
     self.currentSort.timeStep = speedSlider.get() / float(1000)
     if not correctnessCheck(self.list):
         self.currentSort.kill = False
         self.timeToSort.set('Time to sort: ...')
         self.start = time.time()
         self.currentSort.heapSort(self.list)
         self.stop = time.time()
         self.timeToSort.set(
             'Time to sort: {:.3f} seconds'.format(self.stop -
                                                   self.start))
     checkClick()
     actionText.set("Idle...")
コード例 #4
0
 def mergeClick():  #button that is used to start a merge sort
     stopClick()
     actionText.set("Merge Sorting...")
     if not isinstance(self.currentSort, MergeSort):
         self.currentSort = MergeSort(self,
                                      speedSlider.get() / float(1000),
                                      self.list, self.myPlot)
         self.timeComplexity.set(self.currentSort.getTimeComplexity())
     else:
         self.currentSort.dummyList = self.list
     self.currentSort.timeStep = speedSlider.get() / float(1000)
     if not correctnessCheck(self.list):
         self.currentSort.kill = False
         self.timeToSort.set('Time to sort: ...')
         self.start = time.time()
         self.currentSort.mergeSort(self.list, 0, len(self.list))
         self.myPlot.update(self.list)
         self.stop = time.time()
         self.timeToSort.set(
             'Time to sort: {:.3f} seconds'.format(self.stop -
                                                   self.start))
     checkClick()
     actionText.set("Idle...")