//利用栈实现数制转换(10进制转换8进制)#include<>#include<>#defineERROR0#defineOK1#defineSTACK_INIT_SIZE100//存储空间初始分配量#defineSTACKINCREMENT10//存储空间分配增量typedefintSElemType;typedefstructstack{ SElemType*top; SElemType*bottom; intstacksize;}SqStack;intInitStack(SqStack*S){ //构造一个空栈 S->bottom=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!S->bottom)returnERROR;//存储分配失败 S->top=S->bottom; S->stacksize=STACK_INIT_SIZE; returnOK;}//InitStackintPush(SqStack*S,SElemTypee){ //插入元素e为新的栈顶元素 if(S->top-S->bottom>=S->stacksize-1) { S->bottom=(SElemType*)realloc(S->bottom, (S->stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S->bottom) returnERROR;// S->top=S->bottom+S->stacksize;} *S->top++=e; returnOK;}//PushintPop(SqStack*S,SElemType*e){ //若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR; if
利用栈实现数制转换(10进制转换8进制) 来自淘豆网m.daumloan.com转载请标明出处.