问题:检查一个单向链表,删除其中数据大于100的元素。下面程序错在哪儿? 30
#include<stdio.h>#include<stdlib.h>typedefstructEAM{doublex;structEAM*next;}EMP;struc...
#include<stdio.h>
#include<stdlib.h>
typedef struct EAM
{
double x;
struct EAM *next;
}EMP;
struct typelist
{
EMP *head,*rear;
long len;
}EMPlist;
long creat(EMP *head);
void output(EMP *p);
long delet(EMP *p,int n)
{
EMP *q;
p=q;
p=p->next;
while(p!=NULL)
{
if(p->x>n)
{
q->next=p->next;
EMPlist.len--;
p=q->next;
continue;
}
q=p;
p=p->next;
}
return EMPlist.len;
}
void main()
{
long n;
EMPlist.head=(EMP*)malloc(sizeof(EMP));
EMPlist.head->next=NULL;
EMPlist.rear=NULL;
EMPlist.len=0;
printf("input numbers:\n");
n=creat(EMPlist.head);
printf("\n the result:\n");
output(EMPlist.head);
n=delet(EMPlist.head,100);
printf("\n the result after delet:\n");
output(EMPlist.head);
} 展开
#include<stdlib.h>
typedef struct EAM
{
double x;
struct EAM *next;
}EMP;
struct typelist
{
EMP *head,*rear;
long len;
}EMPlist;
long creat(EMP *head);
void output(EMP *p);
long delet(EMP *p,int n)
{
EMP *q;
p=q;
p=p->next;
while(p!=NULL)
{
if(p->x>n)
{
q->next=p->next;
EMPlist.len--;
p=q->next;
continue;
}
q=p;
p=p->next;
}
return EMPlist.len;
}
void main()
{
long n;
EMPlist.head=(EMP*)malloc(sizeof(EMP));
EMPlist.head->next=NULL;
EMPlist.rear=NULL;
EMPlist.len=0;
printf("input numbers:\n");
n=creat(EMPlist.head);
printf("\n the result:\n");
output(EMPlist.head);
n=delet(EMPlist.head,100);
printf("\n the result after delet:\n");
output(EMPlist.head);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询