This is a creation in Article, where the information may have evolved or changed.
The first time to come to the blog park, belong to the relatively late, after graduation has been engaged in the development of 4 years, learned something, but found that need to learn more things. First two basic sort algorithm hot warm-up
I. Bubble sort, move backwards, from small to large sort, its thought for the adjacent two numbers to compare, will be larger lag, time complexity O (n^2)
Package Mainimport ( "FMT") func main () { array: = [11]int{56,45,9,16,2,89,78,34,102,56,99} FMT. Print ("Pre-order:") FMT. Println (Array) length: = Len (array) for I: = 0, i < length, i++ {for J: = 0, J < Length-1-i, J + + { If ARRAY[J] > array[j+1] { Temp: = Array[j] array[j] = array[j+1] array[j+1] = temp } } } FMT. Print ("Post-order:") FMT. Println (Array)}
Two. Quick sorting, from the back to find a minimum placed in front of the order from small to large, time complexity O (n^2)
Package Mainimport ( "FMT") func main () { //quick sort, from behind to find a smallest placed in front of the position, from small to large sort, time complexity O (n^2) array: = [11]int{ 56,45,9,16,2,89,78,34,102,56,99} length:= len (array) temp,position: = 0,0 fmt. Print ("Pre-order:") FMT. PRINTLN (array) for I: = 0, i < length-1; i++ { position = I for j: = i+1; J < length; J + + { if Arra Y[J] < array[position] { position = J } } //Replace the current I position and position with temp = array[i] array [i] = Array[position] array[position] = temp } fmt. Print ("Post-order:") FMT. Println (Array)}