
大神帮忙看看这个关于栈的程序的问题~~
#include"stdio.h"#include"malloc.h"#defineMAXSIZE100structStack{int*p;int*bottom;int*...
#include "stdio.h"
#include "malloc.h"
#define MAXSIZE 100
struct Stack
{ int *p;
int *bottom;
int *top;
void StackInit();
int Pop();
void Push(int x);
};
void test1(int &sum);
void test(int &sum);
void main()
{
}
void test(int &sum)
{
int x;
scanf("%d",&x);
if (0==x)
{
sum=0;
}
else
{
test(sum);
sum+=x;
}
printf("%d\n",sum);
}
void test1(int &sum)
{
}
void struct Stack::StackInit()
{
p=(int*)malloc(MAXSIZE*sizeof(int));
bottom=p;
top=p;
}
void struct Stack::Push(int x)
{
*top=x;
top++;
}
int struct Stack::Pop()
{
int x=*top;
top--;
return x;
}
编译之后出现错误:
D:\我的程序\数据结构\链表.cpp(72) : fatal error C1004: unexpected end of file found
求指教! 展开
#include "malloc.h"
#define MAXSIZE 100
struct Stack
{ int *p;
int *bottom;
int *top;
void StackInit();
int Pop();
void Push(int x);
};
void test1(int &sum);
void test(int &sum);
void main()
{
}
void test(int &sum)
{
int x;
scanf("%d",&x);
if (0==x)
{
sum=0;
}
else
{
test(sum);
sum+=x;
}
printf("%d\n",sum);
}
void test1(int &sum)
{
}
void struct Stack::StackInit()
{
p=(int*)malloc(MAXSIZE*sizeof(int));
bottom=p;
top=p;
}
void struct Stack::Push(int x)
{
*top=x;
top++;
}
int struct Stack::Pop()
{
int x=*top;
top--;
return x;
}
编译之后出现错误:
D:\我的程序\数据结构\链表.cpp(72) : fatal error C1004: unexpected end of file found
求指教! 展开
3个回答
展开全部
把这几个“struct”去掉试试
void struct Stack::Push(int x)
int struct Stack::Pop()
void struct Stack::StackInit()
void struct Stack::Push(int x)
int struct Stack::Pop()
void struct Stack::StackInit()
展开全部
C++中使用结构体时不用再加struct关键字了,只有定义的时候需要加struct
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
#include "malloc.h"
#define MAXSIZE 100
struct Stack{
int *p;
int *bottom;
int *top;
void StackInit();
int Pop();
void Push(int x);
};
void test1(int &sum);
void test(int &sum);
void main(){
}void test(int &sum)
{
int x;
scanf("%d",&x);
if (0==x)
{
sum=0;
}
else
{
test(sum);
sum+=x;
}
printf("%d\n",sum);
}
void test1(int &sum)
{
}
void Stack::StackInit()
{ p=(int*)malloc(MAXSIZE*sizeof(int));
bottom=p;
top=p;
}
void Stack::Push(int x)
{
*top=x;
top++;
}
int Stack::Pop()
{
int x=*top;
top--;
return x;
}
现在编译没有问题 了
#include "malloc.h"
#define MAXSIZE 100
struct Stack{
int *p;
int *bottom;
int *top;
void StackInit();
int Pop();
void Push(int x);
};
void test1(int &sum);
void test(int &sum);
void main(){
}void test(int &sum)
{
int x;
scanf("%d",&x);
if (0==x)
{
sum=0;
}
else
{
test(sum);
sum+=x;
}
printf("%d\n",sum);
}
void test1(int &sum)
{
}
void Stack::StackInit()
{ p=(int*)malloc(MAXSIZE*sizeof(int));
bottom=p;
top=p;
}
void Stack::Push(int x)
{
*top=x;
top++;
}
int Stack::Pop()
{
int x=*top;
top--;
return x;
}
现在编译没有问题 了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询