Package sort;//=================================================//File name:shellsort//------------------------- -----------------------------------------------------//Author:commonimport java.util.arrays;//class name: arrays_shell// Properties://Method: Class Arrays_shell{private int[] arrays;private int curnum;public arrays_shell (int max) {//Create an empty array of max length super ( ); arrays = new Int[max];curnum = 0;} public void Insert (int value) {//empty array add element arrays[curnum] = value;curnum++;} public void display () {//display array System.out.println (arrays.tostring (Arrays));} public void Shellsort () {int out,in;int temp;int h = 1;while (H <= curnum/3)//Find maximum increment, 5 initial increment is 4h = h*3+1;//1,4,13,40,121 ,.... while (h>0) {for (out=h;out<curnum;out++) {//out increments from 1, sorts 22 before out, temp = Arrays[out];in = Out;while (in> H-1 && arrays[in-h] >= temp) {//Just start in is the size of comparison 0 and h arrays[in] = Arrays[in-h];in = h;} Arrays[in] = Temp;//display ();} h = (h-1)/3;}}} Main class//function:shellsortpublic class Shellsort {public static void main (STRIng[] args) {//TODO auto-generated method stub int maxSize = 100; Arrays_shell Arrays_demo = new Arrays_shell (maxSize); Arrays_demo.insert (; arrays_demo.insert); Arrays_ Demo.insert (Arrays_demo.insert); arrays_demo.insert; Arrays_demo.display (); Arrays_demo. Shellsort (); Arrays_demo.display ();}}
Java sorting algorithm--Hill sort