Ad
Code
Diff
  • package main
    
    import "fmt"
    
    func swap(dataset []int, a, b int) {
      var x int = dataset[a]
      dataset[a] = dataset[b]
      dataset[b] = x
    }
    
    func bubble_sort(dataset []int){
      for i := 0; i <= len(dataset)-1; i++ {
        for j := len(dataset)-1; j >= i + 1; j-- {
          if dataset[j] < dataset[j-1] {
            swap(dataset, j, j - 1)
          }
        }
      }
    }
    
    
    func main(){
    
      dataset := []int{5, 2, 4, 6, 1, 3};
    
      fmt.Println(dataset)
    
      bubble_sort(dataset);
    
      fmt.Println(dataset)
    }
    
    • package main
    • import "fmt"
    • func swap(dataset []int, a, b int) {
    • var x int = dataset[a]
    • dataset[a] = dataset[b]
    • dataset[b] = x
    • }
    • func bubble_sort(dataset []int, amout_of_integers int){
    • for i := 0; i <= amout_of_integers; i++ {
    • for j := amout_of_integers; j >= i + 1; j-- {
    • func bubble_sort(dataset []int){
    • for i := 0; i <= len(dataset)-1; i++ {
    • for j := len(dataset)-1; j >= i + 1; j-- {
    • if dataset[j] < dataset[j-1] {
    • swap(dataset, j, j - 1)
    • }
    • }
    • }
    • }
    • func main(){
    • dataset := []int{5, 2, 4, 6, 1, 3};
    • fmt.Println(dataset)
    • bubble_sort(dataset, 5);
    • bubble_sort(dataset);
    • fmt.Println(dataset)
    • }