Skip to content

Commit 1ab56fc

Browse files
seong954tegonSchiele
authored andcommitted
Selection_Sort Golang (egonSchiele#35)
* recursion_Golang * go_fmt * selection_sort_Golang * rm-golang * selection_sort_Golang * selection_sort_Golang * selection_sort_Golang * dynamic_golang
1 parent d0ac45b commit 1ab56fc

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import "fmt"
4+
5+
// Finds the smallest value in an array
6+
func findSmallest(arr []int) int {
7+
// Stores the smallest value
8+
smallest := arr[0]
9+
10+
// Stores the index of the smallest value
11+
smallest_index := 0
12+
for i := 1; i < len(arr); i++ {
13+
if arr[i] < smallest {
14+
smallest = arr[i]
15+
smallest_index = i
16+
}
17+
}
18+
return smallest_index
19+
}
20+
21+
// Sort array
22+
func selectionSort(arr []int) []int {
23+
size := len(arr)
24+
newArr := make([]int, size)
25+
for i := 0; i < size; i++ {
26+
// Finds the smallest element in the array and adds it to the new array
27+
smallest := findSmallest(arr)
28+
newArr[i] = arr[smallest]
29+
arr = append(arr[:smallest], arr[smallest+1:]...)
30+
}
31+
return newArr
32+
}
33+
34+
func main() {
35+
s := []int{5, 3, 6, 2, 10}
36+
fmt.Println(selectionSort(s))
37+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
import "fmt"
3+
4+
func main(){
5+
if word_a[i] == word_b[j] {
6+
cell[i][j] = cell[i-1][j-1]+1
7+
}else{
8+
cell[i][j] = max(cell[i-1][j], cell[i][j-1])
9+
}
10+
}

0 commit comments

Comments
 (0)