程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c語言-@C語言數據結構大神:順序棧求n!。13行的錯誤怎麼修改?為啥說我定義棧錯誤?

c語言-@C語言數據結構大神:順序棧求n!。13行的錯誤怎麼修改?為啥說我定義棧錯誤?

編輯:編程綜合問答
@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();
}

圖片說明

最佳回答:


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved