struct ListNode{
int value;
ListNode* next;
};
void add_to_tail(ListNode **head,int value)
{
ListNode *p_value = new ListNode();
p_value->value = value;
p_value->next = NULL;
ListNode *p = *head;
if(*head == NULL){
*head = p_value;
}else {
while(p->next != NULL)
p = p->next;
p->next = p_value;
}
}
//找到含有某值的第一个节点并删除之。
void remove_node(ListNode **head,int value)
{
if(head == NULL && *head == NULL)
return;
ListNode *p_delete_node = NULL;
if((*head)->value == value){
p_delete_node = head;
*head = (*head)->next;
}else{
ListNode *pNode = *head;
while(pNode->next != NULL)
{
if(pNode->next->value == value){
p_delete_node = pNode->next;
pNode->next = pNode->next->next;
break;
}
pNode = pNode->next;
}
}
if(p_delete != NULL){
delete p_delete;
p_delete = NULL;
}
}