Java Implementation Hill sort algorithm _java

Source: Internet
Author: User

The basic idea of Hill sort algorithm is to take an integer D1 less than n as the first increment, and divide all the records into D1 groups. All records that are multiples of the DL are placed in the same group. First in each group of direct interpolation sort; Then, take the second increment d2<d1 repeat the grouping and sorting above until the incremental dt=1 (DT<DT-L<...<D2<D1) is taken, that is, all records are placed in the same group for direct insertion sort. The method is essentially a grouping insertion method.

Insert sort with increments public
static void Shellsort (int[] array) {
    int len = array.length;
    int h = 1;
    while (H < len)
      h = h * 3 + 1;
    while (H >= 1) {for
      (int i = 1; i < Len; i++) {for
        (int j = i; J >= h; j = j-h) {
          if (array[j) &L T Array[j-h]) {
            Sort.swap (array, J, j-h);//Swap J and J-h
          } else break
            ;
        }
      h = H/3;
    }
  }

Hill Sort Sketch

The above is the entire content of this article, I hope to be proficient in the Java Hill sort of help.

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.