On the understanding of several sorting methods in C language __c language

Source: Internet
Author: User

1, select the Sort method: Each loop, assuming that the first digit in the array to be compared is the maximum (small) number, followed by the remaining number of comparisons, to find out the largest (small) number in the array to be sorted, to take out the first position, Then find a maximum (small) number from the rest of the data and put it behind the last largest (small) number, one at a time until there is only one final number left. (Simple thinking, large amount of calculation, suitable for small data sorting.) )

2, bubble Sort method: Suppose to talk about arrays from small to large sort, in the first round of the cycle, from the last number to the penultimate number, the smaller is placed in the penultimate position, the larger is placed in the final position, and then the penultimate is compared to the last third, and the smaller is placed in the third-lowest position, Place the larger person in the second-lowest position ... Sequentially to the smallest number to the first position, and then the above method is sorted for other numbers except the first number until the last digit is left. The bubble method is the transfer of the smallest (large) number between adjacent numbers. (large amount of computation, suitable for small number of array sorting.) )

3, the exchange of sorting: The same bubble method is the difference is that the bubble method is to match the conditions of the array from the adjacent position before the transmission, and the Exchange method is the number of eligible for a position exchange, will be in line with the number of places in a position directly to that position exchange. (large amount of computation, suitable for small number of sorting)

4, insert method sorting: Take the first number as the base position of the station pile, and then remove another number, put in the appropriate position. Can be called in turn the team law. (large amount of calculation, suitable for sorting decimal groups)

5, the folding method of sorting: The use of recursion, every time to remove the median, (if it is from small to large sort) from left to right first in order compared to the number of the left-hand side, less than the number of the left, swap position, and then from right to left to the right of the number and now the median comparison, less than the median, with the median exchange position, The left side of the median value is less than the median, and the number to the right of the median is greater than the median value. Then the recursive method is used to sort the sub arrays of the left and right sides. (for the sort of large data).

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.