Talk C Chestnut Bar (31st time: C-language example-General sort summary)

Source: Internet
Author: User


Ladies and gentlemen, crossing, the last time we were talking about a quick sort of example, let's not say an example, let's talk about what we said earlier.

Sort to summarize. Gossip Hugh, words return to the positive. Let's talk C chestnuts together!


Crossing, we said in the previous few time the use of various sorting algorithms, they each have their own characteristics, I am here to do a unified summary:


The easy-to- understand sorting algorithm is bubble sort, and it's easy to implement, but it's relatively low performance. The hardest to understand is the quick sort, but

Its performance is the best . Insert sort and select sort in terms of ease of understanding and performance, between bubble sort and hill sort. Hill

Sorting is an upgraded version of the sort that is inserted, and it is easy to understand the sort of hill after inserting the sort. And the performance of the hill sort is better than the insert sort

High, but lower than the fast sort.


The performance I said above is only relative , and each sort algorithm can perform its performance advantage under certain conditions. We say that some

The sort algorithm has high performance and is an average . For example, in the previous examples, the number of elements in the container is 10.

After comparing the worst-performing bubble sort and the performance of the best quick sort, we can see that they are executed the same time and will show you

Example. This is because the number of elements in the container is small, so the advantages of fast sequencing are not shown. Therefore, everyone in the work, can be based on

The actual situation to choose a different sorting algorithm, if not pay attention to performance, then choose an easy to implement the sorting algorithm can be, so write

Out of the program is also easy to read. If the sort of content is not much, the use of a medium-performance hill sort is a good choice if the sort of inside

, it is best to use fast, high-performance sorting.


Crossing, here are the results I tested with the time command in the Linux terminal for your reference. You can modify the elements in the container

Number to test the performance of each sorting algorithm.


Time./bubblesort //test bubble Sort by

The ELMT of array is:

70 27 52 96 38 83 35 0 85 50

After sort, the elmt of an array is:

0 27 35 38 50 52 70 83 85 96


Real 0m0.002s//program run time

User 0m0.000s

SYS 0m0.000s


Time./quicksort //test for quick sort

The ELMT of array is:

36 73 41 0 37 21 94 91 26 98

After sort, the elmt of an array is:

0 21 26 36 37 41 73 91 94 98


Real 0m0.002s //program run time

User 0m0.000s

SYS 0m0.000s


Crossing, if you forget the principles of these sorts, click on the links below to view them:

To find out, bubble sort, click here

To find out, insert sort, click here

To learn more about the hill sort, please click here

To find out, select Sort, click here

To find out, quick Sort, click here


You crossing, the summary of the sort we're going to talk about here. I want to know what the following example, and listen to tell.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk C Chestnut Bar (31st time: C-language example-General sort summary)

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.