qq_31750507 2015-12-05 22:37 采纳率: 52.6%
浏览 1337
已采纳

@C语言数据结构大神:顺序栈求n!。13行的错误怎么修改?为啥说我定义栈错误?

 # include<stdio.h>
# include<stdlib.h>
# define Max_Size 50
typedef struct{//typedef是小写开头! 
//注意此处的top是整形指针 
    int data[Max_Size];
    int top;
}SeqStack,*PSeqStack;


void Init_SeqStack(PSeqStack S)
{
    S->top=-1;//哪里错了?求解释! 
}


int Full_SeqStack(PSeqStack S)
{
    if(S->top==Max_Size-1) return 1;
    else return 0;
}


int Empty_SeqStack(PSeqStack S)
{
    if(S->top==-1) return 1;
    else return 0;
}


void Push_SeqStack(PSeqStack S,int n)
{
    if(Full_SeqStack(S)==1) exit(0);

    else
    {S->top=++S->top;//及时先加一个空间 
     S->data[S->top]=n;}//栈也有data域! 
}


void Pop_SeqStack(PSeqStack S,int n)//*n也是指针 
{   
    if(Empty_SeqStack(S)==1) printf("UnderFlow\n");

    else
     {n=S->data[S->top];
      S->top=--S->top;}//及时退一个空间 
}


int fact(int n,int f,PSeqStack S)//调用函数为什么不对?求解释! 
{   
    Init_SeqStack(S);
    while(n!=0)
    {
    Push_SeqStack(S,n);
    n=n-1;
    }

    f=1;

    while(Empty_SeqStack(S)!=1)
    {
     Pop_SeqStack(S,n);
     f=f*n;
    }
    return f;
}


int main()
{   
    int n,f;SeqStack *S;
    printf("input n:\n");
    scanf("%d",&n);
    printf("%d\n",fact(n,f,S));

    getch();
}

图片说明

  • 写回答

4条回答

  • threenewbee 2015-12-06 00:44
    关注

    int n,f;SeqStack *S;
    ->
    int n,f;SeqStack *S = (SeqStack *)malloc(sizeof(SeqStack));

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。