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