用顺序栈进行数制转换时只有conversion里的InitStack(S)一直报错,不管怎么加定义都只会出现更多的错误,求解
#define MAXSIZE 100
#include
#include
#include
using namespace std;
typedef int Sqstack;
typedef struct InitStack;
//栈结构体定义
typedef struct
{
int *base;
int *top;
int stacksize;
} SqStack;
//栈的初始化
int InitStack(SqStack &S)
{
S.base = new int [MAXSIZE];
if (!S.base)
return 0;
S.top = S.base;
S.stacksize = MAXSIZE;
return 1;
}
//入栈
int Push(SqStack& S, int e)
{
if (S.top - S.base == S.stacksize) //判断栈满
return 0;
*S.top++ = e;
return 1;
}
//出栈
int Pop(SqStack& S, int &e)
{
if (S.top == S.base) //判断栈空
return 0;
e = *--S.top;
return 1;
}
int conversion(int N,int n)
{
int e;
InitStack(S);
while(N)
{
Push(S,N%n);
N=N/n;
}
while(!SqStack(S))
{
Pop(S,e);
cout<int main()
{
SqStack S;
InitStack(S);
int arry[2]={2,8};int i;
for(i=0;i<2;i++)
conversion(10,arry[i]);
return 0;
}
[Error] 'S' was not declared in this scope
int conversion(int N,int n) 这个函数里面 S没有定义。