sorting algorithm (C #)

Source: Internet
Author: User

1. Insert Sort

1.1 Direct Insert Sort

Algorithm Introduction:

The way to insert a sort directly (straight insertion sort) is to remove the first element from the unordered table each time, insert it into the proper position of the ordered table, and make the ordered table still orderly.   The first two numbers are compared, then the second number is inserted into the ordered table by size, and the second one scans the third data with the first two numbers, inserts the third number into the ordered table by size, and then goes through the n-1 scan to complete the sorting process.   The direct insert sort is a stable sort, the worst time complexity is O (n^2), and the spatial complexity is O (1). A direct insert sort consists of a two-layer nested loop. The outer loop identifies and determines the value to be compared. The inner loop determines its final position for the value to be compared. A direct insert sort compares the value to be compared to its previous value, so the outer loop starts with the second value. The current value continues to loop compared with a value larger than what is to be compared until it is found to be smaller than the value to compare and the value to be compared is placed in a subsequent position, ending the cycle. It is worth noting that we have to use a storage space to save the current value to be compared, because when a trip is completed, we want to compare the value to be compared to the value of a smaller than it is the next insertion sort like playing cards in the process of organizing the cards. The basic method for inserting a sort is to insert a record to be sorted by the size of its keyword into the appropriate position in the previously sorted sequence, each step until all records have been inserted. Algorithm Code:

1.2 Hill Sort

2. Exchange sort

2.1 Bubble Sort

2.2 Quick Sort

3. Select sort

3.1 Direct Selection sort

3.2 Heap Sorting

4. Merge sort

5. Base Order

sorting algorithm (C #)

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: 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.