pseudocode with FOR
for j = n − 1 to 1 step − 1 do
does this means开发者_Go百科 for all j in [1 .. n-1] or [2 .. n-1] ?
for j = n − 1 to 1 step − 1 do
is a countdown.
It will start at j and count down to 1 (inclusive).
So if j is 6, then it will go down 5, 4, 3, 2, 1.
twist: Now if your j is a negative value, then you should consider that it will go upto the min negative first, then rollover to the max positive and then count down to 1.
If n=5 then the for loop is executed 4 times with J equal to 4 then 3, then 2, and finally 1 in that order
Seems pretty clear to me. That means it counts down from n-1 to 1.
精彩评论