题目中设计了一个数制转换算法SZZH,将十进制制数n转换为m进制数。这个算法中调用了顺序栈的一些基本操作,由于某程序员使用的是别人栈的基本操作,里面丢了一些语句(已经标出了位置,共有4处),请你补全这些基本语句。
# include<stdio.h>
# include<malloc.h>
# include<stdlib.h>
# define OK 1
# define ERROR 0
typedef int ElemType;
# define STACK_INITSIZE 8
# define STACK_INCREAMENT 2
typedef struct node
{
ElemType *elem;
int top;
int stacksize;
} SeqStack;
int InitStack(SeqStack *S)
{
S->elem=(ElemType *)malloc(sizeof(ElemType)*STACK_INITSIZE);
if(!(S->elem))
return ERROR;
S->stacksize=STACK_INITSIZE;
S->top=0;
return OK;
}
int Push(SeqStack *S,ElemType e)
{
ElemType *newbase,newspacesize;
if(S->top>=S->stacksize-1)
{
newspacesize=(S->stacksize+STACK_INCREAMENT)*sizeof(ElemType);
newbase=(ElemType *)realloc(S->elem,newspacesize);
if(!newbase)
return ERROR;
S->elem=newbase;
S->stacksize+=STACK_INCREAMENT;
}
S->elem[S->top]=e;
S->top++;/*语句1,请补充*/
return OK;
}
int Pop(SeqStack *S,ElemType *e)
{
if(S->top<=0)
return ERROR;
*e=S->elem[S->top-1]/*语句2,请补充*/;
S->top--;
return OK;
}
int StackEmpty(SeqStack *S)
{
if(S->top<=0/*语句3,请补充*/)
return 1;
else
return 0;
}
void SZZH(int n,int m)
{
int n1,ys,e;
SeqStack S;
InitStack(&S);
n1=n;
while(n1>0)
{
ys=n1%m;
Push(&S,ys);/*语句4,请补充*/;
n1=n1/m;
}
while(!StackEmpty(&S))
{
Pop(&S,&e);
if(e<=9)
printf("%d",e);
else
printf("%c",'A'+e-10);
}
printf("\n");
}
int main()
{
int n,m;
scanf("%d,%d",&n,&m);
SZZH(n,m);
}