Package sufa import (" FMT ""math" "math/rand" "strconv" "time") func Main2() {var li []int var r int var start, end int64 //li = []int{90, 23, 433, 343, 53, -1, 56, 7, 7, 8, 6, 45, 4, 5, 66, 7} li = []int{} for i := 0; i < 10; i++ { r = rand.Intn(100) li = append(li, r) } //for i := len(li)-1; i >= 0; i-- { //// fmt.Println(i, li[i]) // var t = li[0] // for j := 1; j < len(li); j++ { // if li[j] < li[j-1] { // t = li[j-1] // li[j-1] = li[j] // li[j] = t // } // } //} fmt.Println(li) start = time.Now().UnixNano() //BubbleSort(li) //SelectSort(li) //InsertSort(li) //ShellSort(li) //MergeSort(li) //QuickSort(li) //CountSort(li) BucketSort(li) //Reverse(li) //ExChange(li, 0,1) end = time.now ().UnixNano() fmt.println (li) fmt.println (end-start) len(li) - 1; i >= 0; i-- { // fmt.Println(i, li[i]) var t = li[0] for j := 1; j < len(li); j++ { if li[j] < li[j-1] { t = li[j-1] li[j-1] = li[j] li[j] = t } } fmt.Print(i, "\r")}} // SelectSort(Li []int) {for I := 0; i < len(li); i++ { var minIndex int = i for j := i; j < len(li); j++ { if li[j] < li[minIndex] { minIndex = j } } ExChange(li, i, InsertSort(I []int) {for I := 1; i < len(li); i++ { var this int = li[i] for j := i - 1; j >= 0; j-- { if li[j+1] < li[j] { ExChange(li, j, J +1) continue} if li[j+1] >= li[j] {li[j+1] = this break}}}} // func shellSort (li []int) {var l = Len (li) var gap = l / 2 if l <= 1 { return } for true { if gap == 1 { InsertSort(li) break } for i := 0; i < gap; i++ { var index int var group []int = make([]int, 0) var groupIdList []int = make([]int, 0) //group = append(group, li[i]) //groupIdList = append(groupIdList, i) for j := 0; j < l; j++ { index = i + j*gap if index >= l { break } group = append(group, li[index]) groupIdList = append(groupIdList, index) } InsertSort(group) for j := 0; j < len(groupIdList) && j < len(group); j++ { var ind int if len(groupIdList) <= 1 || len(group) <= 1 { break } ind = groupIdList[j] li[ind] = group[j] } } gap = gap / 2 } } func MergeSort(li []int) { //merge(li, 0, len(li)) type funcType func(li []int, left, right int) var f funcType f = func(li []int, left, right int) { var middle = (left + right) / 2 if right-left <= 1 { InsertSort(li[left:right]) return } f(li, left, middle) f(li, middle, right) SelectSort(li[left:middle]) SelectSort(li[middle:right]) } f(li, 0, Len (li))} // QuickSort(li []int) {// Qu (li, 0, len(li)) if len(li) <= 1 { return } type funcType func(li []int, left, right int) var f funcType f = func(li []int, left, right int) { var pivot int = (right + left) / 2 if right-left <= 1 { InsertSort(li[left:right]) return } f(li, left, pivot) f(li, pivot, right) //fmt.Println(li[left:right], li[pivot]) for i := pivot - 1; i >= left; i-- { if li[i] >= li[pivot] { for j := i; j < pivot; j++ { ExChange(li, j, j+1) //if j+1 == pivot { // pivot -= 1 //} } pivot -= 1 } } for i := right - 1; i > pivot; i-- { if li[i] <= li[pivot] { for j := i; j > pivot; j-- { ExChange(li, j, j-1) } pivot += 1 } } SelectSort(li[left:pivot]) SelectSort(li[pivot:right]) //fmt.Println(li[left:right], li[pivot]) } f(li, 0, Var (min = li[0] Max = li[0] ma []int res []int) {var (min = li[0] Max = li[0] ma []int res []int); i < len(li); i++ { if li[i] <= min { min = li[i] } if li[i] >= max { max = li[i] } } ma = make([]int, max+1) for i := 0; i < len(li); i++ { ma[li[i]] += 1 } res = make([]int, 0) for i := 0; i < len(ma); i++ { if ma[i] ! = 0 { for j := 0; j < ma[i]; j++ { res = append(res, i) } } } for i := 0; i < len(li); i++ { li[i] = res[i] } //fmt.Println(ma, min, max, Func []int) {var Max = li[0] var maxNumb = 0 for I := 0; i < len(li); i++ { if li[i] >= max { max = li[i] } } var data = strconv.Itoa(max) maxNumb = len(data) for i := 0; i < maxNumb; i++ { var l = make([][]int, len(li)*2) var n = 0 for j := 0; j < len(li); j++ { n = getNumb(li[j], i) //fmt.Println(n, li[j], i) l[n] = append(l[n], li[j]) } var index = 0 for j := 0; j < 10; j++ { if len(l[j]) > 0 { for k := 0; k < len(l[j]); K ++ {li[index] = l[j][k] index++}}}}} Index int) int {return (num/int(math.pow (10, float64(index)))) % 10}) func ExChange(li []int, x, int) Y int) {var t int t = li[x] li[x] = li[y] li[y] = t} // func Reverse(li []int) {for I := 0; i < len(li)/2; i++ { ExChange(li, i, len(li)-i-1) } }