Merge sort of Go first contact

Source: Internet
Author: User

Just started to touch the go language, some do not adapt, the whole and C somewhat similar, so it is not too difficult to learn, but just contact also feel that go in many aspects of the strong. Master the basic grammar of Go, simply write a merge sort exercise:

1 Package Main2 3 Import (4     "FMT"5 )6 7 func hebing (arr []int8, left int8, mid int8, right int8) {8     varARR2 [Ten]int89I, J: = left, Mid +1TenCNT: =0 One      forI <= mid && J <=Right { A         ifArr[i] <Arr[j] { -ARR2[CNT] =Arr[i] -CNT + =1 thei + =1 -}Else { -ARR2[CNT] =Arr[j] -CNT + =1 +J + =1 -         } +     } A      forI <=Mid { atARR2[CNT] =Arr[i] -CNT + =1 -i + =1 -     } -      forJ <=Right { -ARR2[CNT] =Arr[j] inCNT + =1 -J + =1 to     } +      forTM1, TM2: =0, left; TM2 <= right; TM1, tm2 = TM1 +1, TM2 +1 { -ARR[TM2] =ARR2[TM1] the     } * } $ Panax Notoginseng func mergesort (arr []int8, left int8, right int8) { -     ifLeft >=Right { the         return +     } AMid: = (left + right)/2 the FMT. Println (left, Mid, right) + mergesort (arr, left, mid) -MergeSort (arr, Mid +1, right) $ hebing (arr, left, Mid, right) $ } -  - Func Main () { the     vararr = []int8{1,4,2,5,3} -MergeSort (arr,0,4)Wuyi FMT. Println (arr) the}

Merge sort of Go first contact

Related Article

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.