我的程序出错,高手来看看!!!急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/18 06:11:22
建立一个链表,从键盘输入数据,删除链表中值相同的结点。
程序代码如下:
#include "iostream.h"
#define Null 0
struct LNode
{
float date;
struct LNode *next;
};
int n=0;
struct LNode *creat()
{
struct LNode *head,*p1,*p2;
cout<<"输入0时结束!"<<endl;
p1=p2=head=new LNode;
head->date=Null;
head->next=Null;
while(p1->date!=0)
{
p1=new LNode;
cin>>p1->date;
p2->next=p1;
p2=p1;
n++;
}
p2->next=Null;
return head;
}
struct LNode *Delete(struct LNode *head)
{
int i,j;
struct LNode *p1,*p2,*p,*del;
p=p1=p2=head->next;
for(i=1;i<=n;i++)
{
p1=p2=p;
p1=p->next;
while(p!=Null)
{
if(p->date==p1->date)
{
del=p1;
p2->next=p1->next;
p1=p1->next;
delete del;
}
else

楼上回答正确 Delete函数丢了一个“}”

可惜我不能加分……

改完后,程序的确可以通过编译,但是有两个warning
1.Delete缺少一个返回值(我写的是 return head;)
2.你定义的 int i,j; 中 j 没有用到

建议,编程要有个好习惯,这样提高的才比较快,欲祝成功。

Delete函数丢了一个“}”!
另:LNode在使用时不需要再前面使用struct关键字,float类型数值不要用==和!=来比较大小。