File tree Expand file tree Collapse file tree 13 files changed +69
-65
lines changed Expand file tree Collapse file tree 13 files changed +69
-65
lines changed Original file line number Diff line number Diff line change 1- class_name BogoSort
2- extends ComparisonSort
1+ """
2+ BOGOSORT
33
4- const NAME = "BOGOSORT"
5- const ABOUT = """
64Generates random permutations until the array is sorted.
7- """
8- const CONTROLS = """
5+
96Keep on hitting RIGHT ARROW to CONTINUE and hope for the best!
107"""
118
9+ class_name BogoSort
10+ extends ComparisonSort
11+
1212func _init (array ).(array ):
1313 pass
1414
Original file line number Diff line number Diff line change 1- class_name BubbleSort
2- extends ComparisonSort
1+ """
2+ BUBBLE SORT
33
4- const NAME = "BUBBLE SORT"
5- const ABOUT = """
64Bubble sort iterates through the array and looks at each pair of
75elements, swapping them if they are out of order. When it has gone
86through the entire array without swapping a single pair, it has
97finished. Though simple to understand, bubble sort is hopelessly
108inefficient on all but the smallest of arrays.
11- """
12- const CONTROLS = """
9+
1310If the two highlighted elements are out of order, hit LEFT ARROW to swap
1411them. Otherwise, hit RIGHT ARROW to continue.
1512"""
1613
14+ class_name BubbleSort
15+ extends ComparisonSort
16+
1717const ACTIONS = {
1818 "SWAP" : "Left" ,
1919 "CONTINUE" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name CocktailSort
2- extends ComparisonSort
1+ """
2+ COCKTAIL SORT
33
4- const NAME = "COCKTAIL SORT"
5- const ABOUT = """
64Cocktail shaker sort is a variation of bubble sort that
75alternates going backwards and forwards.
8- """
9- const CONTROLS = """
6+
107If the two highlighted elements are out of order, hit LEFT ARROW to swap
118them. Otherwise, hit RIGHT ARROW to continue.
129"""
1310
11+ class_name CocktailSort
12+ extends ComparisonSort
13+
1414const ACTIONS = {
1515 "SWAP" : "Left" ,
1616 "CONTINUE" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name CombSort
2- extends ComparisonSort
1+ """
2+ COMB SORT
33
4- const NAME = "COMB SORT"
5- const ABOUT = """
64Comb sort is a variant of bubble sort that operates on gapped arrays.
7- """
8- const CONTROLS = """
5+
96If the two highlighted elements are out of order, hit LEFT ARROW to swap
107them. Otherwise, hit RIGHT ARROW to continue.
118"""
129
10+ class_name CombSort
11+ extends ComparisonSort
12+
1313const SHRINK_FACTOR = 1.3
1414const ACTIONS = {
1515 "SWAP" : "Left" ,
Original file line number Diff line number Diff line change @@ -11,9 +11,13 @@ const EFFECTS = {
1111}
1212
1313const DISABLE_TIME = 1.0
14+ var NAME = _get_header ().split (" " )[0 ]
15+ var DESCRIPTION = _get_header ().split (" " )[1 ]
16+ var CONTROLS = _get_header ().split (" " )[2 ]
1417
1518var array : ArrayModel
1619var moves = 0
20+ var test = _get_header ().split (" " )[0 ]
1721
1822var _timer = Timer .new ()
1923
@@ -26,6 +30,9 @@ func _init(array):
2630 self .connect ("mistake" , self , "_on_ComparisonSort_mistake" )
2731 self .connect ("done" , self , "_on_ComparisonSort_done" )
2832
33+ func _get_header ():
34+ return get_script ().source_code .replace ("\n " , " " ).split ('"""' )[1 ].strip_edges ()
35+
2936func _ready ():
3037 set_process_input (false )
3138
Original file line number Diff line number Diff line change 1- class_name InsertionSort
2- extends ComparisonSort
1+ """
2+ INSERTION SORT
33
4- const NAME = "INSERTION SORT"
5- const ABOUT = """
64Insertion sort goes through the array and inserts each
75element into its correct position. It is most similar to how most people
86would sort a deck of cards. It is also slow on large arrays but it is
97one of the faster quadratic algorithms. It is often used to sort smaller
108subarrays in hybrid sorting algorithms.
11- """
12- const CONTROLS = """
9+
1310Hit LEFT ARROW to swap the two highlighted elements as long as they are
1411out of order. When this is no longer the case, hit RIGHT ARROW to
1512advance.
1613"""
1714
15+ class_name InsertionSort
16+ extends ComparisonSort
17+
1818const ACTIONS = {
1919 "SWAP" : "Left" ,
2020 "CONTINUE" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name MergeSort
2- extends ComparisonSort
1+ """
2+ MERGE SORT
33
4- const NAME = "MERGE SORT"
5- const ABOUT = """
64Merge sort is an efficient sorting algorithm that splits the array into
75single-element chunks. Then it merges each pair of chunks until only one
86sorted chunk is left by repeatedly choosing the smaller element at the
97head of each chunk and moving the head back. However, it needs an entire
108array's worth of auxiliary memory.
11- """
12- const CONTROLS = """
9+
1310Press the ARROW KEY corresponding to the side that the smaller
1411highlighted element is on. If you've reached the end of one side, press
1512the other side's ARROW KEY.
1613"""
1714
15+ class_name MergeSort
16+ extends ComparisonSort
17+
1818const ACTIONS = {
1919 "LEFT" : "Left" ,
2020 "RIGHT" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name QuickSort
2- extends ComparisonSort
1+ """
2+ QUICKSORT
33
4- const NAME = "QUICKSORT"
5- const ABOUT = """
64Quicksort designates the last element as the pivot and puts everything
75less than the pivot before it and everything greater after it. This
86partitioning is done by iterating through the array while keeping track
97of a pointer initially set to the first element. Every time an element
108less than the pivot is encountered, it is swapped with the pointed
119element and the pointer moves forward. At the end, the pointer and pivot
1210are swapped, and the process is repeated on the left and right halves.
13- """
14- const CONTROLS = """
11+
1512If the highlighted element is less than the pivot or the pivot has been
1613reached, press LEFT ARROW to swap it with the pointer. Otherwise, press
1714RIGHT ARROW to move on.
1815"""
1916
17+ class_name QuickSort
18+ extends ComparisonSort
19+
2020const ACTIONS = {
2121 "SWAP" : "Left" ,
2222 "CONTINUE" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name SelectionSort
2- extends ComparisonSort
1+ """
2+ SELECTION SORT
33
4- const NAME = "SELECTION SORT"
5- const ABOUT = """
64Selection sort incrementally builds a sorted array by repeatedly looking
75for the smallest element and swapping it onto the end of the sorted
86portion of the array, which initially starts with size zero but grows
97after each round. It is faster than an unoptimized bubble sort but
108slower than insertion sort.
11- """
12- const CONTROLS = """
9+
1310Keep on hitting RIGHT ARROW until you encounter an element that is
1411smaller than the left highlighted element, then hit LEFT ARROW and
1512repeat.
1613"""
1714
15+
16+ class_name SelectionSort
17+ extends ComparisonSort
18+
1819const ACTIONS = {
1920 "SWAP" : "Left" ,
2021 "CONTINUE" : "Right" ,
Original file line number Diff line number Diff line change 1- class_name ShellSort
2- extends ComparisonSort
1+ """
2+ SHELL SORT
33
4- const NAME = "SHELL SORT"
5- const ABOUT = """
64Shell sort is a variation of insertion sort that sorts arrays separated
75by gaps.
8- """
9- const CONTROLS = """
6+
107Hit LEFT ARROW to swap the two highlighted elements as long as they are
118out of order. When this is no longer the case, hit RIGHT ARROW to
12- advance.
139"""
1410
11+ class_name ShellSort
12+ extends ComparisonSort
13+
1514const ACTIONS = {
1615 "SWAP" : "Left" ,
1716 "CONTINUE" : "Right" ,
You can’t perform that action at this time.
0 commit comments