Home > Java > javaTutorial > body text

Examples of Hill sorting among eight sorting algorithms in Java development

无忌哥哥
Release: 2018-07-23 09:59:04
Original
1288 people have browsed it

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;
			}
		}
	}
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template