排序

选择排序 AND 冒泡排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import "fmt"

func main() {

array := []int{1,2,3,10,5}

for i:=1;i<len(array);i++{
for j:=0;j<len(array)-i;j++ {
if array[j] < array[j+1] {
array[j],array[j+1] = array[j+1],array[j]
}
}
}

fmt.Println(array)


array1 := []int{10,20,30,5,50}

for i:=0;i<len(array1)-1;i++ {
for j:=i+1;j<len(array1);j++{
if array1[j] < array1[i] {
array1[i],array1[j] = array1[j],array1[i]
}
}
}
fmt.Println(array1)
}