This is a creation in Article, where the information may have evolved or changed.
Golang practice Finding the maximum value in the array, flipping the maximum value to the end of the queue, and then turning the maximum value to the team head.
package mainimport ("FMT")//arr 2,5,3,1,4//arr 2,4,1,3func revert (arr []int) {for I,j:=0,len (arr)-1; i<j; i,j=i+1,j-1 {arr[i], arr[j]=arr[j], arr[i]//fmt. Print (arr)}}func findmaxpos (arr []int) (pos int) {max:=0for i:=0; I<len (arr); i++ {if arr[i] > max {max, pos=arr[i], I}}return pos}//Test Revertfunc Test_revert () {var arr0 = []int{2,5,3,1,4}var arr1 = []int{2,4,1,3}fmt]. Print (ARR0) revert (ARR0) fmt. Print (arr1) revert (arr1)}func method1 (arr []int) {fmt. Print ("Start arr:") fmt. Print (arr) fmt. Print ("/n") for i:=0; I<len (arr); i++ {fmt. Printf ("Turn%d:/n", i) fmt. Print (arr[i:]) fmt. Print ("/n") pos: = Findmaxpos (arr[i:]) pos+=ifmt. Printf ("max:%d, Max pos:%d/n", Arr[pos],pos) revert (Arr[pos:]) fmt. Print (arr) fmt. Print ("/n") revert (Arr[i:]) fmt. Print (arr) fmt. Print ("/n")}fmt. Print (arr)}func main () {var arr0 = []int{2,5,3,1,4}method1 (arr0)}