十进制转八进制C++源代码
发布时间:2021-06-06
发布时间:2021-06-06
十进制转八进制C++源代码
C++源代码文辑 代码名称:十进制转换为八进制
编程工具: Microsoft Visual C++ 6.0
作 者:长风夜雨
十进制转八进制C++源代码
#define STACKINCREMENT 10;
#define OVERFLOW 0
#define OK 1
#define ERROR 0
typedefstruct
{
int *base;
int *top;
intstacksize;
} SqStack;
intInitStack (SqStack *S)
{// 构造一个空栈S
S->base = (int *)malloc( 100 * sizeof(int));
if (!S->base) return OVERFLOW; //存储分配失败
S->top = S->base;
S->stacksize = STACK_INIT_SIZE;
return OK;
};
int Push (SqStack *S, int e)
{
if (S->top - S->base >= S->stacksize) //栈满,追加存储空间
{
S->base = (int *) realloc( S->base,
(S->stacksize + 10) *
sizeof (int));
if (!S->base) return OVERFLOW; //存储分配失败
S->top = S->base + S->stacksize;
S->stacksize += STACKINCREMENT;
};
*S->top++ = e;
return OK;
};
int Pop (SqStack *S, int *e)
{ // 若栈不空,则删除S的栈顶元素,
// 用e返回其值,并返回OK;
// 否则返回ERROR
if (S->top == S->base) return ERROR;
*e = *--S->top;
return OK;
};