回覆列表
  • 1 # 使用者6767156913043

    連結串列的清空操作,就是要銷燬掉除表頭結點之外的所有結點。只要寫個迴圈來銷燬結點就可以,注意,要先記錄當前結點的後繼結點,然後再銷燬當前結點。

    參考程式碼:

    #define OK 1

    #define ERROR 0

    typedef int ElemType;

    typedef struct SqList{

    ElemType elem;

    struct SqList *next;

    }SqList;

    int ClearList(SqList *list)

    {

    SqList *temp, *head = list;

    if (list == NULL)

    return ERROR;

    list = list->next;

    while (list != NULL)

    {

    temp = list->next;

    free(list);

    list = temp;

    }

    head->next = NULL;

    return OK;

    }

  • 中秋節和大豐收的關聯?
  • 杜蘭特是勇士最“窩囊”的超級巨星!忍氣吞聲屢次被格林嗆聲怒吼為哪般?