Skip to content

Commit a07db0d

Browse files
committed
Code enhancements
1 parent 26e7fe3 commit a07db0d

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

main.go

-50
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66
"time"
77

8-
"github.com/gookit/color"
98
"github.com/manifoldco/promptui"
109
)
1110

@@ -125,55 +124,6 @@ func main() {
125124
}
126125
}
127126

128-
func printAlgorithmDescription(algorithm int) {
129-
switch algorithm {
130-
case BubbleSort:
131-
color.Bold.Println(color.Yellow.Sprint("Bubble Sort"))
132-
fmt.Println()
133-
fmt.Println(color.Cyan.Sprint("Bubble Sort is a simple comparison-based sorting algorithm. It works by repeatedly stepping through the list to be sorted,"))
134-
fmt.Println(color.Cyan.Sprint("compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list"))
135-
fmt.Println(color.Cyan.Sprint("is sorted. The algorithm gets its name from the way smaller elements 'bubble' to the top of the list."))
136-
case SelectionSort:
137-
color.Bold.Println(color.Yellow.Sprint("Selection Sort"))
138-
fmt.Println()
139-
fmt.Println(color.Cyan.Sprint("Selection Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into two parts:"))
140-
fmt.Println(color.Cyan.Sprint("the sorted part and the unsorted part. The algorithm repeatedly selects the minimum element from the unsorted part"))
141-
fmt.Println(color.Cyan.Sprint("and moves it to the end of the sorted part. This process continues until the entire list is sorted."))
142-
case InsertionSort:
143-
color.Bold.Println(color.Yellow.Sprint("Insertion Sort"))
144-
fmt.Println()
145-
fmt.Println(color.Cyan.Sprint("Insertion Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into two parts:"))
146-
fmt.Println(color.Cyan.Sprint("the sorted part and the unsorted part. The algorithm repeatedly picks an element from the unsorted part and inserts"))
147-
fmt.Println(color.Cyan.Sprint("it into the correct position in the sorted part. This process continues until the entire list is sorted."))
148-
case GnomeSort:
149-
color.Bold.Println(color.Yellow.Sprint("Gnome Sort"))
150-
fmt.Println()
151-
fmt.Println(color.Cyan.Sprint("Gnome Sort is an in-place comparison-based sorting algorithm. It works by repeatedly comparing adjacent elements."))
152-
fmt.Println(color.Cyan.Sprint("If the two elements are in the wrong order, it swaps them and moves one step backward. If the two elements"))
153-
fmt.Println(color.Cyan.Sprint("are in the correct order, it moves one step forward. This process continues until the entire list is sorted."))
154-
case CocktailShakerSort:
155-
color.Bold.Println(color.Yellow.Sprint("Cocktail Shaker Sort"))
156-
fmt.Println()
157-
fmt.Println(color.Cyan.Sprint("Cocktail Shaker Sort, also known as Bidirectional Bubble Sort, is a variation of Bubble Sort. It works by repeatedly"))
158-
fmt.Println(color.Cyan.Sprint("sorting the list in both directions, first from the beginning to the end (like Bubble Sort), and then from the end"))
159-
fmt.Println(color.Cyan.Sprint("to the beginning. The algorithm stops when the list becomes sorted."))
160-
case CombSort:
161-
color.Bold.Println(color.Yellow.Sprint("Comb Sort"))
162-
fmt.Println()
163-
fmt.Println(color.Cyan.Sprint("Comb Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into a series of"))
164-
fmt.Println(color.Cyan.Sprint("gaps and repeatedly sorting the list with a specific shrink factor. The shrink factor reduces the gaps until it becomes 1."))
165-
fmt.Println(color.Cyan.Sprint("At this point, the algorithm behaves similar to Bubble Sort. Comb Sort is an improvement over Bubble Sort for large lists."))
166-
case OddEvenSort:
167-
color.Bold.Println(color.Yellow.Sprint("Odd-Even Sort"))
168-
fmt.Println()
169-
fmt.Println(color.Cyan.Sprint("Odd-Even Sort is an in-place comparison-based sorting algorithm. It works by repeatedly comparing and swapping"))
170-
fmt.Println(color.Cyan.Sprint("adjacent elements at even and odd indices. The process continues until the list is sorted. Odd-Even Sort is known"))
171-
fmt.Println(color.Cyan.Sprint("for its simplicity but is not very efficient for large lists."))
172-
default:
173-
fmt.Println("Invalid selection")
174-
}
175-
}
176-
177127
func runAlgorithm(algorithm int, arr []int, delay time.Duration) {
178128
switch algorithm {
179129
case BubbleSort:

utils.go

+49
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,52 @@ func visualizeIteration(c Color, array []int, idx1, idx2 int, delay time.Duratio
101101
time.Sleep(delay)
102102
clearConsole()
103103
}
104+
105+
func printAlgorithmDescription(algorithm int) {
106+
switch algorithm {
107+
case BubbleSort:
108+
color.Bold.Println(color.Yellow.Sprint("Bubble Sort"))
109+
fmt.Println()
110+
fmt.Println(color.Cyan.Sprint("Bubble Sort is a simple comparison-based sorting algorithm. It works by repeatedly stepping through the list to be sorted,"))
111+
fmt.Println(color.Cyan.Sprint("compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list"))
112+
fmt.Println(color.Cyan.Sprint("is sorted. The algorithm gets its name from the way smaller elements 'bubble' to the top of the list."))
113+
case SelectionSort:
114+
color.Bold.Println(color.Yellow.Sprint("Selection Sort"))
115+
fmt.Println()
116+
fmt.Println(color.Cyan.Sprint("Selection Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into two parts:"))
117+
fmt.Println(color.Cyan.Sprint("the sorted part and the unsorted part. The algorithm repeatedly selects the minimum element from the unsorted part"))
118+
fmt.Println(color.Cyan.Sprint("and moves it to the end of the sorted part. This process continues until the entire list is sorted."))
119+
case InsertionSort:
120+
color.Bold.Println(color.Yellow.Sprint("Insertion Sort"))
121+
fmt.Println()
122+
fmt.Println(color.Cyan.Sprint("Insertion Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into two parts:"))
123+
fmt.Println(color.Cyan.Sprint("the sorted part and the unsorted part. The algorithm repeatedly picks an element from the unsorted part and inserts"))
124+
fmt.Println(color.Cyan.Sprint("it into the correct position in the sorted part. This process continues until the entire list is sorted."))
125+
case GnomeSort:
126+
color.Bold.Println(color.Yellow.Sprint("Gnome Sort"))
127+
fmt.Println()
128+
fmt.Println(color.Cyan.Sprint("Gnome Sort is an in-place comparison-based sorting algorithm. It works by repeatedly comparing adjacent elements."))
129+
fmt.Println(color.Cyan.Sprint("If the two elements are in the wrong order, it swaps them and moves one step backward. If the two elements"))
130+
fmt.Println(color.Cyan.Sprint("are in the correct order, it moves one step forward. This process continues until the entire list is sorted."))
131+
case CocktailShakerSort:
132+
color.Bold.Println(color.Yellow.Sprint("Cocktail Shaker Sort"))
133+
fmt.Println()
134+
fmt.Println(color.Cyan.Sprint("Cocktail Shaker Sort, also known as Bidirectional Bubble Sort, is a variation of Bubble Sort. It works by repeatedly"))
135+
fmt.Println(color.Cyan.Sprint("sorting the list in both directions, first from the beginning to the end (like Bubble Sort), and then from the end"))
136+
fmt.Println(color.Cyan.Sprint("to the beginning. The algorithm stops when the list becomes sorted."))
137+
case CombSort:
138+
color.Bold.Println(color.Yellow.Sprint("Comb Sort"))
139+
fmt.Println()
140+
fmt.Println(color.Cyan.Sprint("Comb Sort is an in-place comparison-based sorting algorithm. It works by dividing the input list into a series of"))
141+
fmt.Println(color.Cyan.Sprint("gaps and repeatedly sorting the list with a specific shrink factor. The shrink factor reduces the gaps until it becomes 1."))
142+
fmt.Println(color.Cyan.Sprint("At this point, the algorithm behaves similar to Bubble Sort. Comb Sort is an improvement over Bubble Sort for large lists."))
143+
case OddEvenSort:
144+
color.Bold.Println(color.Yellow.Sprint("Odd-Even Sort"))
145+
fmt.Println()
146+
fmt.Println(color.Cyan.Sprint("Odd-Even Sort is an in-place comparison-based sorting algorithm. It works by repeatedly comparing and swapping"))
147+
fmt.Println(color.Cyan.Sprint("adjacent elements at even and odd indices. The process continues until the list is sorted. Odd-Even Sort is known"))
148+
fmt.Println(color.Cyan.Sprint("for its simplicity but is not very efficient for large lists."))
149+
default:
150+
fmt.Println("Invalid selection")
151+
}
152+
}

0 commit comments

Comments
 (0)