Java Insert Sort

Source: Internet
Author: User

The code is as follows:

public class Insertsort {public  static void Insertsort (Datawrap [] data) {System.out.println ("start sort:"); int length = The value of data.length;for (int i = 1;i < length;i++) {datawrap tmp = data[i];//i index is already larger than all values on that side, indicating that it is ordered, without inserting// (The data before the I-1 index is already ordered, the value of the element at the I-1 index is the maximum value) if (Data[i].compareto (data[i-1]) <0) {int J = i-1;//The whole moves back one block for (; J >= 0 & & Data[j].compareto (TMP) >0; j--) {data[j+1] = data[j];} Finally, the value of TMP is inserted in the appropriate position data[j+1] = tmp;} System.out.println (java.util.Arrays.toString (data));}} public static void Main (string[] args) {datawrap[] data = {new Datawrap (""), New Datawrap (""), new Datawrap (49, ""), New Datawrap (""), new Datawrap (+, ""), new Datawrap (9, ""), New Datawrap (-16, "")}; System.out.println ("before sorting: \ n" + java.util.Arrays.toString (data)); Insertsort (data); System.out.println ("After sorting: \ n" + java.util.Arrays.toString (data));}}

  

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