大家好,我正在尝试创建一个删除特定数字的函数 从链接列表中具有此编号的所有单元格中,但我的删除功能仅删除他到达末尾的第一个单元格,然后返回到主单元格 这是我的代码:
struct num* deleteCell(struct num* point, int numdelete)
{
struct num* tempdelete = point;
if (point == NULL) // found the tail and dont found any match to delete
{
printf("not found\n");
return NULL;
}
else if (point->number == numdelete)// found one to delete
{
tempdelete = point->pNext;
free(point);
}
else// Just keep going
{
point->pNext = deleteCell(point->pNext, numdelete);
}
return tempdelete;
}
(point是指向第一个单元格的指针,numdelete是我要删除的数字) 感谢各位帮忙!!!!
单独
最佳答案
struct num* deleteCell(struct num* point, int numdelete) {
if (point == NULL) {
return NULL;
}
if (point->number == numdelete) {
num* tempdelete = point->pNext;
free(point);
return deleteCell(tempdelete, numdelete);
}
point->pNext = deleteCell(point->pNext, numdelete);
return point;
}
关于c - 从链表中删除某些数字(递归),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37709566/