Java Hill Sort

Source: Internet
Author: User

Code from a code cloud

public static void Shellsort (int[] arr) {//Initialize incrementInth = 1;//Calculate maximum interval, formula: H = h * 3 + 1While (H < ARR.LENGTH/3) { h = H * 3 + 1; }//Zoom out increments for sortingWhile (h > 0) { //Insert Sortint Waitinsert;//wait for the number of insertionsint i,j;//i Indicates the current number of subscripts to be inserted, and J indicates the ordinal position of the comparison.For (i = h; i < arr.length; i++) { Waitinsert = Arr[i];//Get the number to be inserted in this roundj = i-h; //Compare position initialization, which is the last position of the ordered sequence, from the back forward //If it is greater than or equal to the size of the value waiting to be inserted, the number is shifted to the right one interval size, then the next comparisonWhile (J >-1 && arr[j] >= waitinsert) {Arr[j +h] = arr[j]; j = J-h;}//The location of the insertion must be the position of the last comparison, that is, the location of the j+h. (Note the timing of the j-h to understand)Arr[j +h] = Waitinsert; }//Zoom out increment, formula: h = (h-1)/3h = (h-1)/3; }  }

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