这是基本的,但我的谷歌搜索只是没有削减它.我知道我必须做一些其他事情来逐个移动数组的值,但是下面的编码给了我相同的项[k]到项目[infinity]的值,等于项目[k].我不明白的是,当我将k值复制到k + 1槽时,如何保留原始k + 1值.
if ( i < numItems) //if i is inside the used boundaries of the array
{
for (int k = i; k < numItems; k++) //shift the array values from point i
{
double temp = 0.0;
temp = items[k];
items[k+1] = temp;
}
items[i] = value; //and insert value into i
}
Run Code Online (Sandbox Code Playgroud)
它必须是递归方法吗?