C # Direct Insert sort

Source: Internet
Author: User

An array of type int as an example

1 namespaceDirect Insert Sort2 {3     class Program4     {5 6         Private Static voidInsert (int[] arrayList)7         {8             BOOLIsinsert =false;9              for(inti =1; i < arraylist.length; i++)Ten             { One                 intValue =Arraylist[i]; A                  for(intj = I1; J >=0; j--) -                 { -                     if(Arraylist[j] >value) the                     { -Arraylist[j +1] =Arraylist[i]; -                     } -                     Else +                     { -                         //found a value smaller than I, +arraylist[j+1] =value; AIsinsert =true; at                          Break; -                          -                     } -                     if(Isinsert = =false) -                     { -arraylist[0] =value; in                     } -  to                 } +             } -  the         } *  $         Static voidMain (string[] args)Panax Notoginseng         { -             int[] data =New[] {5,Ten, +, +, -, -}; the Insert (data); +             foreach(varTempinchdata) A             { theConsole.WriteLine (temp+"  "); +             } - Console.readkey (); $         } $     } -}

C # Direct Insert sort

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.