Java Shell Sort

Source: Internet
Author: User

The code is as follows:

public class Shellsort {public static void Sellsort (Datawrap [] data) {System.out.println ("start sort:"); int length = Data.lengt The h;//h variable holds the variable increment int h = 1;//The maximum value of the increment sequence by h*3+1 while (H <=length/3) {h = h*3+1;} while (h >0) {System.out.println (Value of "===h:" +h+ "= = ="), for (int i = H;i < length;i++) {//When the overall back shift is guaranteed data[i] The value is not lost datawrap TMP = the value at the data[i];//i index is already larger than all previous values, indicating that it is ordered, without inserting//(the data before the I-1 index is ordered, the value of the element at the I-1 index is the maximum) if (Data[i].compareto (Data[i-h]) < 0) {int J = i-h;//whole post-shift H-lattice for (; J >= 0 && Data[j].compareto (tmp) >0; j-=h) {data[j+h] = Data[j] ;} Finally, the value of TMP is inserted in the appropriate position data[j+h] = tmp;} System.out.println (java.util.Arrays.toString (data));} h = (h-1)/3;}} 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)); Sellsort (data); System.out.println ("After sorting: \ n" + java.util.Arrays.toString (data));}}

  

Java Shell Sort

Related Article

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.