#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
int data;
struct Node *next;
}No;
int Add(No *head,int n);
int Delect(No *head,int n);
int main()
{
No *head; //头指针
int array[10]={0,1,2,3,4,5,6,7,8,9};
head=(No*)malloc(sizeof(No));
No *p=head;
No *q=head;
int i=0;
for(;i<10;i++)
{ //创建下一个节点时,要先为该节点分配存储空间,然后才能用上一个节点指向下一个节点
head->data=array[i];
head->next=(No*)malloc(sizeof(No));
head=head->next;
}
head->next=NULL; //尾指针为空
Delect(q,5);
while(p->next!=NULL)
{
printf(" %d",p->data);
p=p->next;
}
return 1;
}
int Delect(No *head,int n)//删除该节点后面的节点
{
No * p=head,*after;
while(p&&p->data!=n)
{
p=p->next;
}
if(!p)
{
printf("\nERROR");
}
else
{
after=p->next;
p->next=after->next;
free(after);
}
return 1;
}