我正在尝试学习如何使用插入排序,这是我使用的主要代码:
for (j = 1; j < num.length; j++) // Start with 1 (not 0)
{
key = num[ j ];
for(i = j - 1; (i >= 0) && (num[ i ] < key); i--) // Smaller values are moving up
{
num[ i+1 ] = num[ i ];
}
num[ i+1 ] = key; // Put the key in its proper location
}
Run Code Online (Sandbox Code Playgroud)
但是,我尝试将 - 更改为 + 以尝试将输出更改为降序,但我更加困惑。
这是我正在使用的完整代码:
public class InsertionSort {
public static void main(String[] args) …Run Code Online (Sandbox Code Playgroud)