Java Binary Insert Sort

Source: Internet
Author: User

The code is as follows:

public class Binaryinsertsort {public static void Binaryinsertsort (Datawrap [] data) {System.out.println ("start sort:"); int length = data.length;for (int i = 1;i < length;i++) {//When overall back shift, the value of guaranteed data[i] is not lost datawrap tmp = data[i];int low = 0;int high = I-1;while (Low <= High) {//Find Low,high Intermediate index int mid = (Low+high)/2;//if the TMP value is greater than low, the value of the high intermediate element if (Tmp.compareto (data[ Mid]) {//>0) {//Limit search in half of the index larger than mid = Mid +1;} else{//limit the search for high = Mid-1 in the half of the index smaller than mid;}} Move all elements of low to I to the whole backwards by one step (int j = i; j > low; j--) {data[j] =data[j-1];} Finally, the value of TMP is inserted into the appropriate position data[low] = 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)); Binaryinsertsort (data); System.out.println ("After sorting: \ n" + java.util.Arrays.toString (data));}}

  

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