-
-
Save oldthreefeng/ff62aa7fada1d7b4c02d20296a9c4970 to your computer and use it in GitHub Desktop.
This file contains 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
package sort | |
type Sorter interface{ | |
Len() int | |
Less(i, j int) bool | |
Swap(i, j int) | |
} | |
func Sort(data Sorter) { | |
for i:=1; i<=data.Len(); i++{ | |
for j:=0; j<=data.len()-i; j++{ | |
if data.Less(i+1, i) { | |
data.Swap(i, i+1) | |
} | |
} | |
} | |
} | |
type IntArray []int | |
func (P *IntArray) Len() int{ return len(p) } | |
func (P *IntArray) Less(i, j int) bool { return p[i]<P[j] } | |
func (P *IntArray) Swap(i, j int) { return p[i], p[j] = p[j], p[i] } | |
func SortInt(a []int) { Sort(IntArray(a)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment