Home  >  Article  >  Java  >  Examples of Hill sorting among eight sorting algorithms in Java development

Examples of Hill sorting among eight sorting algorithms in Java development

无忌哥哥
无忌哥哥Original
2018-07-23 09:59:041241browse

package java面试宝典;

import java.util.Arrays;

public class 希尔排序 {
	public static void main(String[] args) {
		int[] a={6,9,3,5,7,1,8,0,2,4};
		System.out.println(Arrays.toString(a));
		shellSort(a);
		System.out.println(Arrays.toString(a));
	}
	public static void shellSort(int[] a){
		for (int h = a.length/2; h >0; h/=2) {
			for (int i = h; i < a.length; i++) {
				int temp=a[i];
				int j;
				for (j = i; j-h>=0; j-=h) {
					if(temp<a[j-1]){
						a[j]=a[j-h];
					}else{
						break;
					}
				}
				a[j]=temp;
			}
		}
	}
}

The above is the detailed content of Examples of Hill sorting among eight sorting algorithms in Java development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn