Java Sorting Algorithm _ 011 Hill sorting

Source: Internet
Author: User
Package WZS. Sort; import java. util. arrays; // The descending incremental sort. Algorithm Is a high-speed and stable improved version of insert sorting. Public class test_wzs010 {public static void main (string [] ARGs) {int [] intarray = {10, 3, 5, 7, 9, 1, 4, 2, 6, 8}; shellsort (intarray); system. out. println ("sorted:" + arrays. tostring (intarray);} // The Hill sorting public static void shellsort (INT [] ARR) {int increment = 1; while (increment <arr. length) {increment = increment * 3 + 1;} increment = (increment-1)/3; while (increment> = 1) {for (INT I = 0; I <increment; I ++) {insertsort (ARR, I, increment);} increment = (increment-1)/3 ;}// insert sort, this method will be called by hill sorting. This method can also be used directly. The use method is insertsort (); // startindex is the starting index of sorting, and increment is incremental, that is, the space between elements is public static void insertsort (INT [] arr, int startindex, int increment) {for (INT I = startindex + increment; I <arr. length; I + = increment) {Int J = I-increment; int temp = arr [I]; while (j> = startindex & temp <arr [J]) {arr [J + increment] = arr [J]; j-= increment;} arr [J + increment] = temp ;}}}

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.