十进制转N进制(数据结构)

来源:百度知道 编辑:UC知道 时间:2024/04/28 17:58:32
实现要求:利用顺序栈实现数制转换。
付50积分。。。。。。
你这儿个不对。
运行不出来。。

10进制转换b进制
#include <iostream>
const int OK=1;
const int ERROR=0;
const int TRUE=1;
const int FALSE=0;
const int INFEASIBLE=-1;
const int OVERFLOW=-2;
const int STACK_INIT_SIZE=100;
const int STACKINCREMENT=10;
using namespace std;
typedef int Status;
typedef struct SqStack
{int *base;
int *top;
int stacksize;
}SqStack;

//空栈
Status InitStack (SqStack &S) //构造一个空栈S
{S.base = (int*)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S.base) return (OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
} //IniStack

//入栈
Status Push(SqStack &S,int e) //若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR
{if(S.top-S.base>=S.stacksize)
{S.base=(int*) realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)
return(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;}
*