@C语言数据结构大神:顺序栈求n!。13行的错误怎么修改?为啥说我定义栈错误?
#include<stdio.h>#include<stdlib.h>#defineMax_Size50typedefstruct{//typedef是小写开头!//注意...
# include<stdio.h># include<stdlib.h># define Max_Size 50typedef 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++; n=S->data[S->top];}//栈也有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();} 展开
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++; n=S->data[S->top];}//栈也有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();} 展开
2015-12-05
展开全部
#include"stdio.h"
void mian()
{
float average;
int score[10]={99,78,66,89,97,68,77,87,60,100},i,sum=0;
for(i=0;i<10;i++)
sum+=score[i];
average=(float)sum/10;
printf("the average score is %2f\n",average);
}
void mian()
{
float average;
int score[10]={99,78,66,89,97,68,77,87,60,100},i,sum=0;
for(i=0;i<10;i++)
sum+=score[i];
average=(float)sum/10;
printf("the average score is %2f\n",average);
}
追问
不行,必须用顺序栈来实现。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询