C++でスタックで進数間の変換を実現

1538 ワード

    ,        ,   :
 
  
 
  
 
  
#include
using namespace std;
#define STACK_INIT_SIZE 100
struct Stack{
int*base;
int*top;
int stacksize;
};
void conversion();
int InitStack(Stack*S);
int Push(Stack*S,int e);
int Pop(Stack*S,int*e);
int StackEmpty(Stack*S);
int main(){
conversion();
return 0;
}
void conversion(){
//       ,            
Stack S;
    int e;
InitStack(&S);
int n,m;
cout<>n;
cout<>m;
while(n){
   Push(&S,n%m);
   n=n/m;
}
while(!StackEmpty(&S)){
   Pop(&S,&e);
        cout<base=new int[STACK_INIT_SIZE]; 
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return 0;
}
int Push(Stack*S,int e){
*S->top=e;
    S->top++;
return 0;
}
int Pop(Stack*S,int*e){
S->top--;
*e=*S->top;
    return 0;
}
int StackEmpty(Stack*S){
if(S->top==S->base) return 1;
else return 0;
}