萌新疑问:拿到3个AC7个RE,不知道为什么free()函数不能用,但是尝试了各种办法还是
[Error] 'free' was not declared in this scope
然后连编译都过不去。能拿30pts是因为把free注释掉然后奇迹般的骗到分了
各位dalao帮忙看看是有什么问题吗?
#include<stdio.h>
struct node
{
int data;
node *next;
};node *head,*p,*r,*s;
void op1(int x,int y)
{
p=head->next;
while(p->next!=NULL&&p->data!=x)
{
p=p->next;
}
s=new node;
s->data=y;
s->next=p->next;
p->next=s;
return;
}
void op2(int x)
{
p=head->next;
while(p->next!=NULL&&p->data!=x)
{
p=p->next;
}
p=p->next;
if(p->data==NULL)
printf("0");
else
printf("%d\n",p->data);
return;
}
void op3(int x)
{
p=head->next;
while(p->next!=NULL&&p->data!=x)
{
p=p->next;
}
s=new node;
s=p->next;
p->next=s->next;
free(s);
return;
}
int main()
{
int n,ch,x,y;
scanf("%d",&n);
head=new node;
r=head;
p=new node;
p->data=1;
p->next=NULL;
r->next=p;
r=p;
while(n>0)
{
scanf("%d",&ch);
if(ch==1)
{
scanf("%d%d",&x,&y);
op1(x,y);
}
if(ch==2)
{
scanf("%d",&x);
op2(x);
}
if(ch==3)
{
scanf("%d",&x);
op3(x);
}
n--;
}
}