#include <iostream>
using namespace std;
struct node{
int data;
node* next;
};
void remove(node** head, int value)
{
if(head == NULL)
return ;
node** n = head;
node* cur;
while(cur=*n)
{
if(cur->data == value)
{
*n = cur->next;
delete cur;
}
else
n = &(cur->next);
}
}
void build_link(node*& head, int n)
{
head = new node;
head->data = 1;
int i;
node* p = head;
node* q;
for(i=2; i<=n; i++)
{
q = new node;
q->data = i;
p->next = q;
p = q;
}
q->next = NULL;
}
int main(void)
{
int n = 10;
node* head;
build_link(head, n);
remove(&head, 5);
node* p = head;
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
return 0;
}
利用二级指针删除节点
最新推荐文章于 2022-10-03 11:58:56 发布