|
6 | 6 | "os"
|
7 | 7 | "os/exec"
|
8 | 8 | "runtime"
|
9 |
| - "strings" |
10 | 9 | "time"
|
11 | 10 |
|
12 | 11 | "github.com/gookit/color"
|
@@ -44,56 +43,17 @@ func clearConsole() {
|
44 | 43 | }
|
45 | 44 |
|
46 | 45 | func printColoredArray(c Color, array []int, idx1, idx2 int) {
|
47 |
| - var firstSlice string |
48 |
| - var secondSlice string |
49 |
| - var thirdSlice string |
50 |
| - |
51 |
| - if len(array[:idx1]) > 0 { |
52 |
| - firstSlice = strings.Replace(fmt.Sprintf("%v ", array[:idx1]), "[", "", -1) |
53 |
| - firstSlice = strings.Replace(firstSlice, "]", "", -1) |
54 |
| - } |
55 |
| - if idx1 != idx2 && len(array[idx1+1:idx2]) > 0 { |
56 |
| - secondSlice = strings.Replace(fmt.Sprintf("%v ", array[idx1+1:idx2]), "[", "", -1) |
57 |
| - secondSlice = strings.Replace(secondSlice, "]", "", -1) |
58 |
| - } |
59 |
| - if len(array[idx2+1:]) > 0 { |
60 |
| - thirdSlice = strings.Replace(fmt.Sprintf(" %v", array[idx2+1:]), "[", "", -1) |
61 |
| - thirdSlice = strings.Replace(thirdSlice, "]", "", -1) |
62 |
| - } |
63 |
| - |
64 |
| - var str string |
65 |
| - switch c { |
66 |
| - case LightYellow: |
67 |
| - str = firstSlice + |
68 |
| - color.OpUnderscore.Sprint(color.LightYellow.Sprint(array[idx1])) + |
69 |
| - " " + |
70 |
| - secondSlice + |
71 |
| - color.OpUnderscore.Sprint(color.LightYellow.Sprint(array[idx2])) + |
72 |
| - thirdSlice |
73 |
| - case LightBlue: |
74 |
| - if idx1 != idx2 { |
75 |
| - str = firstSlice + |
76 |
| - color.OpUnderscore.Sprint(color.LightBlue.Sprint(array[idx1])) + |
77 |
| - " " + |
78 |
| - secondSlice + |
79 |
| - color.OpUnderscore.Sprint(color.LightBlue.Sprint(array[idx2])) + |
80 |
| - thirdSlice |
| 46 | + fmt.Print("[") |
| 47 | + for i, _ := range array { |
| 48 | + if idx1 == i { |
| 49 | + fmt.Print(color.OpUnderscore.Sprint(color.LightYellow.Sprint(array[idx1]), " ")) |
| 50 | + } else if idx2 == i { |
| 51 | + fmt.Print(color.OpUnderscore.Sprint(color.LightYellow.Sprint(array[idx2]), " ")) |
81 | 52 | } else {
|
82 |
| - str = firstSlice + |
83 |
| - color.OpUnderscore.Sprint(color.LightBlue.Sprint(array[idx1])) + |
84 |
| - " " + |
85 |
| - thirdSlice |
| 53 | + fmt.Print(color.OpUnderscore.Sprint(array[i], " ")) |
86 | 54 | }
|
87 |
| - case White: |
88 |
| - str = firstSlice + |
89 |
| - color.OpUnderscore.Sprint(array[idx1]) + |
90 |
| - " " + |
91 |
| - secondSlice + |
92 |
| - color.OpUnderscore.Sprint(array[idx2]) + |
93 |
| - thirdSlice |
94 | 55 | }
|
95 |
| - |
96 |
| - fmt.Printf("[ %v ]", str) |
| 56 | + fmt.Println("]") |
97 | 57 | }
|
98 | 58 |
|
99 | 59 | func visualizeIteration(c Color, array []int, idx1, idx2 int, delay time.Duration) {
|
|
0 commit comments