#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef struct stack
{
int data[maxsize];//静态栈
int top;
}Stack;
void initStack(Stack* s)
{
s->top=-1;//如果初始化为-1,push函数中就先++,再赋值,如果初始化为0,就就先赋值,再++
}
int isempty(Stack* s)//判断是否空栈
{
return s->top==-1;
}
int isfull(Stack* s)//判断是否栈满
{
return s->top==maxsize-1;
}
void push(Stack* s,int e)
{
if(isfull(s))
{
printf("Stack overflow!\n");
exit(-1);
}
s->data[++(s->top)]=e;
}
int pop(Stack* s)
{
if(isempty(s))
{
printf("no elemtype!\n");
exit(-1);
}
return s->data[(s->top)--];
}
void convertdecimaltobase(int del,int r)
{
Stack s;
initStack(&s);
while(del>0)
{
push(&s,del%r);//把余的结果存入栈中,例如十进制1348,八进制为2504
del=del/r;//第一次余得4,先入栈,就后出栈
}