Introduction to sorting algorithm and its C implementation

Source: Internet
Author: User

The sorting algorithm (sorting algorithm) is an integral part of the computer algorithm. The sorting algorithm is to rearrange a sequence in order of size. Sorting is an old but still challenging question. Donald Knuth's classic book, the third volume of the Art of computer programming, Computer programming, is dedicated to discussing sorting and finding. From the point of disorder to order, from the angle of statistical physics, we can reduce the entropy of the system and increase the order of the system. The characteristic of order is a very useful priori knowledge about the system. Therefore, the sorting algorithm can be used as the basis of other fast algorithms, such as the binary method is based on ordered sequence search algorithm. Until today, the ranking algorithm is still one of the ways in which computer science is actively exploring.

Here I list some of the most common sorting methods and use the C language real

Is. The sequence is represented as an array of an, with an array of n elements. A[i] An element in an array, where I is the position (subscript) of the element in the set. In accordance with the provisions of C, array subscript starting from 0. Assuming that the array is arranged from left to right, the element labeled 0 is at the far left of the array.

The sequence is eventually arranged into a small to large order. The parameter AC in the following function is the number of elements in the array, that is, N.

(C-language array names to the pointer, passed to the function, so you need to pass the number of elements in the array AC to the function, see the "Expert C programming:deep C Secrets" book in detail)

Starting sequence (unsorted)

Ordered series (sorted)

Below the link, there are related algorithms animation legend, strongly recommended to read at the same time.

http://www.sorting-algorithms.com/

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.