public class Combsort {

    private static void swap (int[] a, int i, int j) {
	int temp = a[i];
	a[i] = a[j];
	a[j] = temp;
    }

    private static int newGap(int gap) {
	gap = gap * 10 / 13;
	if (gap < 1)
	    gap = 1;
	if (gap == 9 || gap == 10)
	    gap = 11;
	return gap;
    }

    private static void combsort(int[] a) {
	int gap = a.length;
	for (;;) {
	    gap = newGap(gap);
	    boolean swapped = false;
	    for (int i = 0; i < a.length - gap; i++) {
		if (a [i] > a [i + gap]) {
		    swap(a, i, i + gap);
		    swapped = true;
		}
	    }
	    if (gap == 1 && !swapped)
		break;
	}
    }

    public static void main(String[] args) {
	int[] a = {1, 6, 5, 3, 8, 6, 9, 7, 2, 4, 0};
	combsort(a);
	for (int i = 0; i < a.length; i++)
	    System.out.println(a[i]);
    }

}
