Created
October 23, 2014 16:05
-
-
Save hayamiz/b022a8608c7d090fda8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env go run $0 $@ ; exit | |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
func main() { | |
rand.Seed(0) | |
// generate random number array | |
var data [20]int | |
for i, _ := range data { | |
data[i] = rand.Intn(100) | |
} | |
fmt.Println(data) | |
// sort by Bubble Sort | |
for i := 0; i < len(data) - 1; i++ { | |
for j := 0; j < len(data) - 1; j++ { | |
if data[j] > data[j + 1] { | |
data[j], data[j + 1] = data[j + 1], data[j] | |
} | |
} | |
} | |
// check whether the array is sorted. | |
for i := 0; i < len(data) - 1; i++ { | |
if data[i] > data[i + 1] { | |
panic(i) | |
} | |
} | |
fmt.Println(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment