Algorithm Crash (iii) direct insertion, hill sort and merge ordering of seven classical sorts

Source: Internet
Author: User
Tags join sort sorts

Direct Insert Sort:

This sort of sorting is very good to understand, the real example is that we fight the landlord, when we caught a mess of cards, we have to according to size comb poker, 30 seconds later,

Poker comb finished, 4 3, 5 s, wow ... Remember how we combed it at the time.

The left one card is 3, the second card is 5, the third card is 3, hurriedly inserted into the back of the first card, the fourth card is 3, exultation, hurriedly inserted behind the second one,

The fifth card is 3, ecstasy, Haha, a cannon is produced.

How, the life everywhere is the algorithm, has already melted into our life and the blood.

The following illustration shows:

Look at this picture. I don't know if you can understand, in the insert sort, the array is divided into two types, ordered array blocks and unordered array blocks,

Yes, the first time. Extracts a number of 20 as an ordered array block from the unordered array block.

The second time from the "unordered array block" to extract a number 60 ordered into the "ordered array of blocks", that is, 20,60.

The third time. Similarly, the difference is that 10 is smaller than the ordered array, so the 20,60 position is shifted back, freeing up a position for 10 to insert.

Then you can insert all of them in this pattern.

 using System;   
 Using System.Collections.Generic;   
 Using System.Linq;   
      
 Using System.Text;   
         Namespace Insertsort {public class program {static void Main (string[] args)   
      
             {list<int> List = new List<int> () {3, 1, 2, 9, 7, 8, 6}; Console.WriteLine ("Before:" + string.)   
      
             Join (",", list));   
      
             Insertsort (list); Console.WriteLine ("After Sort:" + string.)   
         Join (",", list));  static void Insertsort (List<int> List) {//No sequence for (int i = 1; i < list.) Count;   
      
                 i++) {var temp = list[i];   
      
                 Int J;   
                     Ordered sequence for (j = i-1 J >= 0 && temp < list[j]; j--) {   
                 List[j + 1] = List[j];   
         }        List[j + 1] = temp; }   
         }   
     }   
 }

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.