Golang Fast Sorting algorithm

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

The go language is really concise, and the following uses it to implement a fast sorting algorithm

Package listen to Qsortfunc listen to quicksort (values listen to []int, listen to the left to listen to int, listen to int) Listen {if listen to left listen < listen right Listen {//Listen set Datum temp listen: = Listen to values[ left]//Listen to set Sentinel I, listen to J listen: = Listen to Left, listen to rightfor listen {//listen to the right-to-go, find the first number smaller than the base value for listening to VALUES[J] Listen >= listen to the temp listen && Listen I listen < listen J Listen {j--}// Listen from left to right, find the first number larger than the benchmark for listen values[i] Listen <= listen to temp && listen I listen < listen to J Listen {i++}//Listen if the Sentinels meet, then exit the loop if listen I listen to >= listen to J Listen {break}// Listen to exchange the values on both sides of the values[i], listen to values[j] Listen = Listen to values[j], listen to values[i]}//listen to the baseline values moved to Sentinel meet point values[left] Listen = listen to values[i]values[i] Listen = listen to temp// Listen to recursion, sort quickSort (values, listen left, listen to i-1) QuickSort (values, listen to i+1, listen to right)}}func listen to QuickSort (values listen to []int) listen {QuickSort (values, listen 0, listen to Len (values)-1)}

This article is from the "Van Star Technology Blog" blog, please be sure to keep this source http://ustb80.blog.51cto.com/6139482/1575230

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.