不會的,因為每個連結串列每個節點都是一個指標結構
舉個例子
連結串列節點的定義:
struct node
{
int val;
node *next;
};
int DeleteElement(node **head, node *deleteMe)
node *elem = *head;
if (deleteMe == *head)
*head = elem -> next;
free(deleteMe);
return 1;
}
while (elem != NULL)
if (elem -> next == deleteMe)//不要誤寫為elem
elem -> next = deleteMe -> next; //這裡連線連結串列,連結串列不會斷開
elem = elem -> next;
return 0;
不會的,因為每個連結串列每個節點都是一個指標結構
舉個例子
連結串列節點的定義:
struct node
{
int val;
node *next;
};
int DeleteElement(node **head, node *deleteMe)
{
node *elem = *head;
if (deleteMe == *head)
{
*head = elem -> next;
free(deleteMe);
return 1;
}
while (elem != NULL)
{
if (elem -> next == deleteMe)//不要誤寫為elem
{
elem -> next = deleteMe -> next; //這裡連線連結串列,連結串列不會斷開
free(deleteMe);
return 1;
}
elem = elem -> next;
}
return 0;
}