题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
StackCreateStack(intMaxElements) { Stackp=(Stack)malloc(sizeof(structStackRecord)); p->Array=(int*)malloc(MaxElements*sizeof(int)); p->Top1=-1; p->Top2=MaxElements; p->Capacity=MaxElements; returnp; } intIsEmpty(StackS,intStacknum) { if(Stacknum==1) { if(S->Top1==-1) return1; return0; } else { if(S->Top2==S->Capacity) return1; return0; } } intIsFull(StackS) { if(S->Top2-S->Top1==1) return1; return0; } intPush(ElementTypeX, StackS, intStacknum) { if(IsFull(S)) return0; if(Stacknum==1) S->Array[++(S->Top1)]=X; elseS->Array[--(S->Top2)]=X; return1; } ElementTypeTop_Pop(StackS,intStacknum) { if(IsEmpty(S,Stacknum)) returnERROR; if(Stacknum==1) returnS->Array[(S->Top1)--]; elsereturnS->Array[(S->Top2)++]; } /*Operation GetOp(){char s[111];scanf("%s",s);if(!strcmp(s,"Push")) return push;if(!strcmp(s,"Pop")) return pop;if(!strcmp(s,"End")) return end;}void PrintStack(Stack S,int Stacknum){while(!IsEmpty(S,Stacknum))printf("%d ",Top_Pop(S,Stacknum));puts("");}*/