#define PUSH_POP_SUCCESS 1
#define PUSH_POP_ERROR 0
struct _stackbuf {
int _collection[STACK_SIZE]
int _top
}
typedef struct _stackbuf S_STACK
typedef unsigned int u_int_f
// 入栈
u_int_f push(S_STACK *stack, int d){
if (stack->_top >= STACK_SIZE) return PUSH_POP_ERROR
stack->_collection[stack->_top++] = d
return PUSH_POP_SUCCESS
}
// 出栈
u_int_f pop(S_STACK *stack, int *e){
if (!stack->_top) return PUSH_POP_ERROR
*e=stack->_collection[--(stack->_top)]
return PUSH_POP_SUCCESS
}
int main(){
S_STACK stack = { {0},0 }
push(&stack, 1)
push(&stack, 2)
push(&stack, 3)
int gv = 0
pop(&stack, &gv)
printf("%d\n", gv)
system("PAUSE")
return 0
}
#define STACKSIZE 100
int mstack[STACKSIZE],top,bottom
void mInitStack() { top=bottom=0}
void mPush(int x) { if ( top-bottom<=STACKSIZE ) { mstack[top]=xtop++} }
int mPop() { int r=0if ( top>bottom ) { r=mstack[top]top--} return r}
void mShowStack() { int iprintf("[")for ( i=bottomi<topi++ ) printf("%d ",mstack[i])printf("]\n")}
void main()
{
int i,n,x,loop=1,s
char buffer[80]
mInitStack()
scanf("%d",&n)for ( i=0i<ni++ ) { scanf("%d",&x)mPush(x)}
mShowStack()
while ( loop )
{ buffer[1]=0gets(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=0break
default: s=0break
}
mShowStack()
}
mShowStack()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)