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
31
|
//冒泡排序
func mpSort(array [] int ) {
for i:= 0 ;i<len(array);i++ {
for j:= 0 ;j<len(array)-i- 1 ;j++ {
if array[j] > array[j+ 1 ] {
array[j], array[j+ 1 ] = array[j+ 1 ], array[j]
}
}
}
}
//快速排序
func quickSort(array [] int , left int , right int ) {
if left < right {
key := array[left]
low := left
high := right
for low < high {
for low < high && array[high] > key {
high--
}
array[low] = array[high]
for low < high && array[low] < key {
low++
}
array[high] = array[low]
}
array[low] = key
quickSort(array, left, low- 1 );
quickSort(array, low+ 1 , right);
}
}
|
以上所述就是本文的全部内容了,希望大家能够喜欢。