1、
例子:删除中间结点3

要找到删除结点的前一个结点
struct node
{
int data;
struct node *next;
};
struct node *p,*q;
q = (struct node *)malloc(sizeof(struct node));
q = head -> next ;
p = q -> next;
q -> next = p -> next ;
free(p);
若没有指针P,只有q,那么
struct node
{
int data;
struct node *next;
};
struct node *q;
q = (struct node *)malloc(sizeof(struct node));
q = head -> next ;
q -> next = q -> next -> next ;
free(q->next);

(2) 删除头结点

struct node
{
int data;
struct node *next;
};
struct node *p; //定义指针p使其指向要删除的头结点
p = (struct node *)malloc(sizeof(struct node));
p = head ;
haed = head -> next; //头指针下移
free(p);

(3)删除为结点

struct node
{
int data;
struct node *next;
};
struct node *p; //定义指针p使其指向要删除的头结点
p = (struct node *)malloc(sizeof(struct node));
p = q -> next ;
q -> next = NULL ; //删除尾结点
free(p);


|