该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
typedef struct data
{
int num;
struct data*next;
}data,*DATA;
DATA createlist();
void abclist(DATA);
void shanchu(DATA ,int );
void main()
{
int a;
DATA head=NULL;
head=createlist();
printf ("这是你输入的数据:");
abclist(head);
printf ("\n请输入你要删除的节点:");
scanf ("%d",&a);
printf ("这是删除操作后的链表:");
shanchu(head,a);
abclist(head);
}
DATA createlist()
{
printf ("请输入一组数据:");
DATA head=(DATA)malloc(sizeof(data));
DATA p;
int a;
p->num=a;
p->next=head->next;
head->next=NULL;
scanf ("%d",&a);
while (a!=0)
{
p=(DATA)malloc(sizeof(data));
p->num=a;
p->next=head->next;
head->next=p;
scanf ("%d",&a);
}
return head;
}
void abclist(DATA head)
{
DATA q=head->next;
while(q)
{
printf("%d ",q->num);
q=q->next;
}
}
void shanchu(DATA head,int a)
{
DATA p=head;
DATA q;
while (p->num!=NULL&&p->num!=a)
{
q=p;
p=p->next;
}
if (p!=NULL)
{
if (q==NULL)
head=p->next;
else
q->next=p->next;
}
return head;
}