*x = L->list[i]; /* Save the deleted element to parameter x */
for(j = i 1; j <= L->size-1; j )
L->list[i] = L->list[i 1];
L->size--; /* The number of data elements is reduced by 1*/
return 1;
我不能完全洗掉節點,而不是這個,它只是替換值,但節點本身沒有被洗掉
uj5u.com熱心網友回復:
在這個 for 回圈中
for(j = i 1; j <= L->size-1; j )
L->list[i] = L->list[i 1];
i此陳述句中使用的變數
L->list[i] = L->list[i 1];
沒有被改變。
看來你的意思
for(j = i 1; j < L->size; j )
L->list[j-1] = L->list[j];
如果陣列list是動態分配的,那么您應該重新分配它,例如
for(j = i 1; j < L->size; j )
L->list[j-1] = L->list[j];
L->size--;
T *tmp = realloc( L->list, L->size * sizeof( *tmp ) );
if ( tmp != NULL ) L->list = tmp;
您將需要替換T為陣列元素的實際型別。我正在使用T,因為您的問題不知道陣列元素的型別是什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/461284.html
