Direct insertion ordering of data structure learning

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/m13666368773/article/details/7506678

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", first time, extract a number 20 from the "unordered array block" as an ordered array block; the second time from the "unordered array block" Extract a number 60 ordered into the "ordered array block", that is, 20,60; third time in the same vein, the difference is that 10 is smaller than the value of an ordered array, so the 20,60 position moves back, freeing a position for 10 to insert, then you can insert all of them by this rule.

1  Packagecom.swust. Insert sort;2 3 Importcom.swust.utils.ArrayUtils;4 5  Public classExample1 {6      Public Static voidMain (string[] args) {7         int[] arr = Arrayutils.createarray (10);8 Arrayutils.showarray (arr);9 sort (arr);TenString string = ""; One String.intern (); A System.out.println (); - Arrayutils.showarray (arr); -     } the      Public Static voidSortint[] list) { -              //No sequence required -              for(inti = 1; i < list.length; i++)   -             {   +                 inttemp = List[i];//10,11,33,1,3 -    +                 intJ;  A                 //If the extracted data is larger than the data in the current ordered array, simply insert it without moving the elements in the array at                  for(j = i-1; J >= 0 && temp < list[j]; j--)   -                 {   -List[j + 1] =List[j];  -                 }   -LIST[J+1] =temp;  -             }   in         } -}

Direct insertion ordering of data structure learning

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.