The time complexity of hill sorting is O (n ^ 1.3 )~ O (N ^ 2), space complexity is O (1 ).
The Code is as follows:
/*** Source code name: shellsort. java * Date: 2014-08-11 * program function: Hill sorting * copyright: [email protected] * Author: a2bgeek */public class shellsort {public void shellsort (INT [] in) {int length = in. length; int span = length/2; int I, j; while (span> = 1) {// selection sort beginfor (I = span; I <length; I ++) {int TMP = in [I]; for (j = I-span; j> = 0 & TMP <in [J]; j-= span) {In [J + SPAN] = in [J];} in [J + SPAN] = TMP;} // selection sort endspan/= 2; printarray (in );}} public void printarray (INT [] In) {for (int I: In) {system. out. print (I + "");} system. out. println ();} public static void main (string [] ARGs) {int [] testcase = {1, 3, 4, 10, 2, 5, 6, 7, 9, 11}; shellsort mshellsort = new shellsort (); mshellsort. printarray (testcase); mshellsort. shellsort (testcase); mshellsort. printarray (testcase );}}