0

大家好,我正在尝试创建一个函数,该函数从链表中具有此数字的所有单元格中删除某个数字,但我的删除函数仅删除他到达末尾的第一个单元格,然后返回到主单元格,这是我的代码:

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 是我要删除的数字)感谢帮助!!!!

阿隆

4

1 回答 1

0
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;
}
于 2016-06-08T19:38:20.563 回答