Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created March 11, 2014 11:35
Show Gist options
  • Save keizo042/9484035 to your computer and use it in GitHub Desktop.
Save keizo042/9484035 to your computer and use it in GitHub Desktop.
golangの単純ソート。
package main
import (
"fmt"
"math/rand"
)
func swap(a int,b int)(int,int){
if a > b {
return b, a
}else {
return a, b
}
}
func main(){
t := make([]int,10)
tmp := [10]int{9,7,8,5,6,4,1,0,2,4}
for i:=range tmp{
for j:=i; j < len(tmp); j++{
tmp[i],tmp[j] = swap(tmp[i],tmp[j])
}
}
for k:=range tmp { fmt.Printf("%d:%d\n",k,tmp[k])}
fmt.Printf("\n")
//swap
for count:=range t { t[count] =rand.Int() }
for k:=range t { fmt.Printf("%d:%d\n",k,t[k])}
fmt.Printf("\n")
for i:=range t{
for j:=i; j < len(t); j++{
t[i],t[j] = swap(t[i],t[j])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment