Java sorting algorithm--Hill sort

Source: Internet
Author: User

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

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.