l543664486 2020-03-31 15:30 采纳率: 100%
浏览 353
已采纳

c语言 函数的定义和调用有点问题,求助

#include
typedef int Status;
typedef int ElemType;
#define Maxsize 20
#define OK 1
#define ERROR 0

typedef struct
{ElemType elem[Maxsize];
int top;
}SqStack;
Status lnitStack(SqStack *S);
Status Push(SqStack *S,ElemType e);
Status Pop(SqStack *S,ElemType *e);
Status GetTop( SqStack S, ElemType *e);
int StackEmpty( SqStack S );
Status zhuanhuan(int x, int n);

Status lnitStack(SqStack *S)
{ S->top=-1;
}

Status Push(SqStack *S,ElemType e)
{if(S->top>=Maxsize-1)
return ERROR;
else{
S->top++;
S->elem[S->top]=e;
return OK;}
}

Status Pop(SqStack *S,ElemType *e)
{
if(S->top==-1)
return ERROR;
*e=S->elem[S->top];
S->top--;
return OK;
}

Status GetTop( SqStack S, ElemType *e)

{
if( S.top == S.base )
return ERROR;

*e = *( S.top – 1 );
return OK;
}

int StackEmpty( SqStack S )
{
if(S.top == S.base)
return 1;
else
return 0;
}

Status zhuanhuan(int x, int y)
{ SqStack S;
int e;
InitStack(&S);
printf("\n\n\t\t未转换的十进制数为:%d\n",x);
while(x)
{ Push(&S,x%n);
x=x/y;
}
printf("\n\t\t转换后的的%d进制数为:",n);
while(!StackEmpty(S))
{ Pop(&S,&e);
printf("%d",e);
}
printf("\n\n");
return OK;
}

int main()
{SqStack S;
int n,e,x,y;
printf("------------\n");
printf("--1.初始化栈--\n");
printf("--2.压栈--\n");
printf("--3.弹栈----\n");
printf("--4.取栈顶元素----\n");
printf("--5.判栈空\n");
printf("--6.十进制数转换成N进制数\n");
printf("--7.退出----\n");
while(1)
{ printf("请选择功能");
scanf("%d",&n);
switch(n)
{

case 1:lnitStack(S);break;
case 2:scanf("%d",&e);Push(S,e);break;
case 3:Pop(S,e);printf("%d\n",e);break;
case 4:GetTop(S,e);printf("%d\n",e);break;
case 5:if(StackEmpty(S))
{
printf("此为空\n");
}
else
printf("此不为空\n");break;
case 6:printf("请输入要转换的十进制数");scanf("%d",&x);
printf("请输入想要的进制数");scanf("%d",&y);
zhuanhuan(x,y);break;
case 7:break;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-04-01 09:39
    关注

    typedef struct
    {ElemType elem[Maxsize];
    int top;
    }SqStack;
    这个里面没有base
    Status GetTop( SqStack S, ElemType *e)

    {
    if( S.top == S.base )
    return ERROR;

    *e = *( S.top – 1 );
    return OK;
    }
    这里的S.base哪里来的?

    感觉你的程序是两个程序拼凑的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器