主题:高手们帮我看看这程序
要求是 顺序线性表的维护,主要功能是建立、查找、删除、修改的功能
编译以后出现两个错误
c:\documents and settings\laigawa\桌面\cpp1.cpp(6) : error C2143: syntax error : missing ';' before '<class-head>'
c:\documents and settings\laigawa\桌面\cpp1.cpp(6) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
Cpp1.obj - 1 error(s), 0 warning(s)
什么原因?
程序如下
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int MAX=100
struct node
{
int data [MAX];
int last;
};
int enter()
{
int x;
printf("what do you want to do?\n
1.creat a node\n
2.search a node\n
3.cancel a node\n
4.change a node\n
5.exit\n");
scanf("%d",&x);
return x;
}
int creat(node list)
{
int x,n,i;
printf("how many nodes do you want it be contained?");
scanf("%d",&n);
if(n>MAX)
{
printf("overflow!\n");
creat(list);
}
elseif(n<0)
{
printf("error input\n");
creat(list);
}
else
{
list.last=n;
for(i=1,i<n,i++)
{
printf("input data of the %d node:",i);
scanf("%d",&list.data[i-1]);
}
return list.last;
}
void find(node list)
{
printf("which do you want to do:\n
1.know the data to find the node\n
2.know the node to find the data\n)
scanf("%c",&n);
switch(n)
{
case 1 :x=findi(node list);
if(n==0)
printf("no find\n");
else
printf("the %d node",x);
break;
case 2 :x=findx(node list);
printf("the %d data",x);
break;
default:
printf("input error\n");
find(list);
}
}
int findi(node list)
{
int n=1,x;
printf("input the data:");
scanf("%d",&x);
while((n<=list.last)&&(list.data[n-1]!=x))
n++;
if (n<=list,last)
return n;
else
return 0;
}
int findx(node list)
{
int x,n;
printf("input the node:");
scanf("%d",n);
if((n>last)||(n<0))
{
printf("input error\n");
x=findx(node list);
}
else
x=list.data[n-1];
return x;
}
void cancel()
{
int n;
printf("which are you aware of:\n
1.the data\n
2.the node\n");
scanf("%d"&n);
switch(n)
{
case 1:cancled(node list);
break;
case 2:canclen(node list);
default:printf("input error\n");
}
}
canceldata(node list)
{
int x,n,i;
printf("delete which data:");
scanf("%d",&n);
x=findi(n);
if((n<=0)||(n>list.last))
{
printf("can not find this data\n");
canceldata(node list);
}
else
for(i=x;i<=(list.last-1);i++)
list.data[i-1]=list.data[i];
}
cancelnode(node list)
{
int n, i;
printf("delete which node:");
scanf("%d",&n);
if((n>list.last)||(n<=0))
{
printf("position is wrong");
cancelnode(node list);
}
else
for(i=n;i<=(list.last-1);i++)
list.data[i-1]=list.data[i];
}
void change(node list)
{
int n;
printf("which are you aware of:\n
1.the data\n
2.the node\n");
scanf("%d"&n);
switch(n)
{
case 1:changedata(node list);
break;
case 2:changenode(node list);
break;
default:printf("input error\n");
change(node list);
}
}
void changenode(node list)
{
int n,x;
printf("change which node:");
scanf("%d",&n);
if((n>list.last)||(n<=0))
{
printf("position is wrong");
changenode(node list);
}
else
{
printf("the new data:");
scanf("%d",&x);
list.data[n-1]=x;
}
}
void changedata(node list)
{
int x,n,i;
printf("change which data:");
scanf("%d",&n);
x=findi(n);
if((x>list.last)||(x<=0))
{
printf("no find the data:");
changed(node list);
}
else
{
printf("the new data:");
scanf("%d",&i);
list.data[x-1]=i;
}
}
main()
{
int n;
node list;
do
{
switch(enter())
{
case 1:
list.last=creat(node list);
break;
case 2:
find(node list);
break;
case 3:
cancel(node list);
list.last--;
break;
case 4:
change(node list);
break;
case 5:
exit(0);
default:
printf("input error\n");
}
}while(1);
}
编译以后出现两个错误
c:\documents and settings\laigawa\桌面\cpp1.cpp(6) : error C2143: syntax error : missing ';' before '<class-head>'
c:\documents and settings\laigawa\桌面\cpp1.cpp(6) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
Cpp1.obj - 1 error(s), 0 warning(s)
什么原因?
程序如下
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int MAX=100
struct node
{
int data [MAX];
int last;
};
int enter()
{
int x;
printf("what do you want to do?\n
1.creat a node\n
2.search a node\n
3.cancel a node\n
4.change a node\n
5.exit\n");
scanf("%d",&x);
return x;
}
int creat(node list)
{
int x,n,i;
printf("how many nodes do you want it be contained?");
scanf("%d",&n);
if(n>MAX)
{
printf("overflow!\n");
creat(list);
}
elseif(n<0)
{
printf("error input\n");
creat(list);
}
else
{
list.last=n;
for(i=1,i<n,i++)
{
printf("input data of the %d node:",i);
scanf("%d",&list.data[i-1]);
}
return list.last;
}
void find(node list)
{
printf("which do you want to do:\n
1.know the data to find the node\n
2.know the node to find the data\n)
scanf("%c",&n);
switch(n)
{
case 1 :x=findi(node list);
if(n==0)
printf("no find\n");
else
printf("the %d node",x);
break;
case 2 :x=findx(node list);
printf("the %d data",x);
break;
default:
printf("input error\n");
find(list);
}
}
int findi(node list)
{
int n=1,x;
printf("input the data:");
scanf("%d",&x);
while((n<=list.last)&&(list.data[n-1]!=x))
n++;
if (n<=list,last)
return n;
else
return 0;
}
int findx(node list)
{
int x,n;
printf("input the node:");
scanf("%d",n);
if((n>last)||(n<0))
{
printf("input error\n");
x=findx(node list);
}
else
x=list.data[n-1];
return x;
}
void cancel()
{
int n;
printf("which are you aware of:\n
1.the data\n
2.the node\n");
scanf("%d"&n);
switch(n)
{
case 1:cancled(node list);
break;
case 2:canclen(node list);
default:printf("input error\n");
}
}
canceldata(node list)
{
int x,n,i;
printf("delete which data:");
scanf("%d",&n);
x=findi(n);
if((n<=0)||(n>list.last))
{
printf("can not find this data\n");
canceldata(node list);
}
else
for(i=x;i<=(list.last-1);i++)
list.data[i-1]=list.data[i];
}
cancelnode(node list)
{
int n, i;
printf("delete which node:");
scanf("%d",&n);
if((n>list.last)||(n<=0))
{
printf("position is wrong");
cancelnode(node list);
}
else
for(i=n;i<=(list.last-1);i++)
list.data[i-1]=list.data[i];
}
void change(node list)
{
int n;
printf("which are you aware of:\n
1.the data\n
2.the node\n");
scanf("%d"&n);
switch(n)
{
case 1:changedata(node list);
break;
case 2:changenode(node list);
break;
default:printf("input error\n");
change(node list);
}
}
void changenode(node list)
{
int n,x;
printf("change which node:");
scanf("%d",&n);
if((n>list.last)||(n<=0))
{
printf("position is wrong");
changenode(node list);
}
else
{
printf("the new data:");
scanf("%d",&x);
list.data[n-1]=x;
}
}
void changedata(node list)
{
int x,n,i;
printf("change which data:");
scanf("%d",&n);
x=findi(n);
if((x>list.last)||(x<=0))
{
printf("no find the data:");
changed(node list);
}
else
{
printf("the new data:");
scanf("%d",&i);
list.data[x-1]=i;
}
}
main()
{
int n;
node list;
do
{
switch(enter())
{
case 1:
list.last=creat(node list);
break;
case 2:
find(node list);
break;
case 3:
cancel(node list);
list.last--;
break;
case 4:
change(node list);
break;
case 5:
exit(0);
default:
printf("input error\n");
}
}while(1);
}