#include <stdio.h>
#include <stdlib.h>
#define STACKSIZE 20
typedef struct sqlist{
int *base;
int *top;
int stacksize;
}SqStack;
void InitStack(SqStack &s){
s.base = new int[STACKSIZE];
if (!s.base){
exit(0);
}
s.top = s.base;
s.stacksize = STACKSIZE;
}
int StackEmpty(SqStack &s){
if (s.base == s.top){
return 1;
} else {
return 0;
}
}
void Push(SqStack &s, int n){
if (s.top - s.base == s.stacksize){
printf("栈满");
exit(0) ;
}
*s.top ++ = n;
}
void Pop(SqStack &s, int &e){
if (s.top == s.base){
printf("栈空");
exit(0) ;
}
e = *--s.top;
}
void jinZhi(SqStack &S, int num, int k){
int x, e;
char ch[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
do{
x = num % k;
num /= k;
Push(S, x);
}while(num);
printf("转换后的%d进制的数值为:", k);
while(StackEmpty(S) != 1){
Pop(S, e);
printf("%c",ch[e]);
}
}
int main(){
SqStack S;
InitStack(S);
jinZhi(S, 1500, 16);
}