十进制转化为八进制--栈实现
//十进制转化为八进制
#include <iostream>
using namespace std;
#define OK 1
#define MAXSIZE 100
#define ERROR 0
#define OVERFLOW -1
typedef int Status;
typedef int SElemtype;
typedef struct Stacknode{
SElemtype data;
struct Stacknode *next;
}Stacknode,*Linkstack;
Status Initstack(Linkstack &S){
S=NULL;
return OK;
}
Status Push(Linkstack &S,SElemtype e){
Stacknode *p;
p=new Stacknode;
p->data=e;
p->next=S;
S=p;
return OK;
}
Status Pop(Linkstack &S,SElemtype e){
Stacknode *p;
p=new Stacknode;
if(S==NULL) return ERROR;
e=S->data;
p=S;S=S->next;
delete p;
return OK;
}
Status Stackempty(Linkstack &S){
Stacknode *p;
if(S==NULL) return 0;
return 1;
}
void conversion(){
Linkstack S;
Initstack(S);
int N;
SElemtype e;
cin>>N;
while(N){
Push(S,N%8);
N=N/8;
}
while(!Stackempty(S)){
Pop(S, e);
cout<<e;
}
}
int main(){
conversion();
}