Classical algorithm: The realization of selecting sort, inserting sort and bubble sort

Source: Internet
Author: User

The object to be sorted is divided into two parts, one sorted, one unordered, one lowest from the unsorted part, and the last one in the sorted section above. For example:

Sort before: 70 80 31 37 10 1 48 60 33 80

[1] 80 31 37 10 70 48 60-33 80 Select a minimum value of 1

[1 10] 31 37 80 70 48 60 33 80 Select the minimum value 10

"[1 10 31] 37 80 70 48 60 33 80" Select the minimum value 31

[1 10 31 33] 80 70 48 60 37 80 ...

[1 10 31 33 37] 70 48 60 80 80 ...

[1 10 31 33 37 48] 70 60 80 80 ...

[1 10 31 33 37 48 60], 70 80 80 ...

[1 10 31 33 37 48 60 70] 80 80 ...

[1 10 31 33 37 48 60 70 80] 80 ...

C # instance:

private static void Selsort ()
 {
     int[] num = new int[] {m, 1, Panax Notoginseng, n
     . int length = num. Length;
     int min, temp;
     
     Writenumline (num);
     
     for (int i = 0; i < length; i++)
     {
         min = i;
         for (int j = i; j < length; J +)
         {
             if (Num[min] > Num[j])
                 min = j;
         }
         if (i!= min)
         {
             temp = num[i];
             Num[i] = num[min];
             Num[min] = temp;
         }
         Writenumline (num);
     }
     
     Writenumline (num);
 }
     
 private static void Writenumline (int[] num)
 {
     foreach (int i in num)
     {
         Console.Write (i + "");
     }
     Console.WriteLine ();
 }

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.