java shellsort

java shellsort

This time I will write the code about shellsort.

ShellSort.java


public class ShellSort {
	public static void sort(int[] array) {
		int h;

		for(h=1;h<array.length/9;h=h*3+1) {

		}

		for(;h>0;h/=3) {
			for(int i=h;i<array.length;i++) {
				int j=i;
				while(j>=h && array[j-h]>array[j]) {
					int temp = array[j];
					array[j] = array[j-h];
					array[j-h] = temp;
					j -= h;
				}
			}
		}
	}
	public static void main(String args[]) {
		int[] array = {3,2,4,5,1};
		sort(array);
		for(int i=0;i<array.length;i++) {
			System.out.print(array[i]);
		}
	}
}

Next time I'll try quicksort.

Recommended Posts

java shellsort
Shellsort
Java
Java
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
java (override)
java (method)
Java Day 2018
Java string
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface
Java9 collection
Java basics
Java methods