Skip to content

Commit deb469e

Browse files
committed
Add Bubble Sort in Go language
1 parent 4db1212 commit deb469e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Sorting/bubblesort.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func bubbleSort(arrayItem []int) {
8+
9+
for i := 0; i < len(arrayItem)-1; i++ {
10+
for j := 0; j < len(arrayItem)-i-1; j++ {
11+
if arrayItem[j] > arrayItem[j+1] {
12+
temp := arrayItem[j]
13+
arrayItem[j] = arrayItem[j+1]
14+
arrayItem[j+1] = temp
15+
}
16+
}
17+
}
18+
19+
}
20+
21+
func main() {
22+
23+
arrayItem := []int{2, 4, 1, 8, 3, 5, 9}
24+
fmt.Println("Original: ", arrayItem)
25+
bubbleSort(arrayItem)
26+
fmt.Println("Sorted: ", arrayItem)
27+
28+
}

0 commit comments

Comments
 (0)