#define Size 100
#define ok 0
#define error 1
#include<iostream>
#include<fstream>
typedef int Status;
typedef int SElemType;
using namespace std;
typedef struct //定义顺序栈
{
int* base;
int* top;
int stacksize;
}Sqstack;
Status InitStack(Sqstack& S)//初始化
{
S.base = new int[Size];
if (!S.base) exit(OVERFLOW); //存储分配失败
S.top = S.base; //初始为空栈
S.stacksize = Size;
return ok;
}
Status Push(Sqstack& S, SElemType e)//入栈
{
if (S.top - S.base == S.stacksize) return error;//栈满
*S.top++ = e;
return ok;
}
Status Pop(Sqstack& S, SElemType& e) //出栈
{
if (S.base == S.top) return error;//栈空
e = *--S.top;
return ok;
}
void conversion(int a)
{
Sqstack S;
InitStack(S);
int i, k;
i = a;
while ((a/8)!= 0)
{
i = a % 8;
Push(S, i);
}
while (S.base != S.top)
{
Pop(S, k);
cout << k;
}
}
void main()
{
int a;
cout << "请输入一个十进制数:";
cin >> a;
conversion(a);
}
宏定义放头文件下面,void main 改成 int main(){return 0;}