#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef struct SNode{
int data;
struct SNode *next;
}SNode,*LinkStack;
Status InitStack(LinkStack &S){
S=NULL;
return OK;
}
bool StackEmpty(LinkStack &S){
if(!S)
return true;
return false;
}
Status Push(LinkStack &S,int e){
SNode *p=new SNode;
if(!p)
return OVERFLOW;
p->data=e;
p->next=S;
S=p;
return OK;
}
Status Pop(LinkStack &S,int &e){
SNode *p;
if(!p)
return ERROR;
e=S->data;
p=S;
S=S->next;
delete p;
return OK;
}
void conversion(){//函数的作用是对一个十进制进行转换
LinkStack S;
int n,m;
InitStack(S);
cout<<"请输入一个十进制数:"<<endl;
cin>>n;
while(n){
Push(S,n%8);
n/=8;
}
cout<<"该数字转换成八进制数后的结果为:"<<endl;
while(!StackEmpty(S)){
Pop(S,m);
cout<<m;
}
}
int main(){
conversion();
return 0;
}