Golang Study 01 Programming Beauty 1.3

Source: Internet
Author: User
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)}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.