发布网友 发布时间:2022-05-05 17:07
共2个回答
热心网友 时间:2022-06-27 19:51
#define STACKSIZE 100
int mstack[STACKSIZE],top,bottom;
void mInitStack() { top=bottom=0; }
void mPush(int x) { if ( top-bottom<=STACKSIZE ) { mstack[top]=x; top++; } }
int mPop() { int r=0; if ( top>bottom ) { r=mstack[top]; top--; } return r; }
void mShowStack() { int i; printf("["); for ( i=bottom;i<top;i++ ) printf("%d ",mstack[i]); printf("]\n"); }
void main()
{
int i,n,x,loop=1,s;
char buffer[80];
mInitStack();
scanf("%d",&n); for ( i=0;i<n;i++ ) { scanf("%d",&x); mPush(x); }
mShowStack();
while ( loop )
{ buffer[1]=0; gets(buffer); s=1;
switch ( buffer[1] )
{ case 'O':
case 'o': x=mPop(); break;
case 'U':
case 'u': x=atoi(buffer+5); mPush(x); break;
case 'n':
case 'N': loop=0; break;
default: s=0; break;
}
mShowStack();
}
mShowStack();
}
热心网友 时间:2022-06-27 19:52
#include<stdio.h>