Shell-sort algorithm variations in Java

前端 未结 2 388
死守一世寂寞
死守一世寂寞 2021-01-20 17:38

Is there a way to calculate the starting point of a for loop and the adjustments to it. The original loop has these conditions

for( int gap = a.length / 2; g

2条回答
  •  一个人的身影
    2021-01-20 18:25

    The "k" value is the element of the sequence. So your for loop would probably look something like:

        for (int k = 0; (Math.pow(3, k) - 1) / 2 <= Math.ceil(n / 3); k++) {
            int gap = (int) ((Math.pow(3, k) - 1) / 2);
            ...
        }
    

提交回复
热议问题