Skip to content

Commit

Permalink
added bubblesort in golang
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishkrishan1995 committed Oct 6, 2018
1 parent 2d7e5ef commit 755be61
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Sorting/bubbleSort/golang/bubbleSort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
)

var toBeSorted [10]int = [10]int{1,3,2,4,8,6,7,2,3,0}

func bubbleSort(input [10]int) {
// n is the number of items in our list
n := 10
swapped := true
for swapped {
swapped = false
for i := 1; i < n-1; i++ {
if input[i-1] > input[i] {
fmt.Println("Swapping")
// swap values using Go's tuple assignment
input[i], input[i-1] = input[i-1], input[i]
swapped = true
}
}
}
fmt.Println(input)
}


func main() {
fmt.Println("Hello World")
bubbleSort(toBeSorted)

}

0 comments on commit 755be61

Please sign in to comment.