Quick sort and bubble sort for version Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

has been very little contact with the algorithm and the like (I use PHP), I suddenly looked at it today and written out in the go language. Like the go language very much, there may be

A little Google complex bar ~. The hair is recorded here, but also hope to be the same as my beginners help.

Here is the code, note that in go to pass the array parameter will be automatically converted to slice, and slice is a reference type , sorting algorithm is not good or bad I do not judge, nor very understand.

Bubble sort func mpsort (array []int) {for I:=0;i<len (array), i++ {for J:=0;j<len (array)-i-1;j++ {if array[j] > Array[j +1] {array[j], array[j+1] = array[j+1], array[j]}}}}//Quick sort func quickSort (array []int, left int, right int) {if left < R ight {key: = Array[left]low: = Lefthigh: = Rightfor Low < high {to low < high && Array[high] > key {high --}array[low] = Array[high]for Low < high && Array[low] < key {Low++}array[high] = Array[low]}array[low] = k Eyquicksort (array, left, low-1), QuickSort (array, low+1, right);}}


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.