#include <stdio.h>
#include<stdlib.h>
#define max 100
typedef struct stack{
int top;
int data[max];
}*pstack,stack;
pstack init(){
pstack s=(pstack)malloc(sizeof (stack));
if(s)
s->top=-1;
return s;
}
void push(pstack s,int x){
if(s->top==max-1){
printf("man");
}else {
s->top++;
s->data[s->top]=x;
}
}
void pop(pstack s,int *x)
{
if(s->top==-1){
printf("栈空");
}else {
*x=s->data[s->top];
s->top--;
printf("-->%d\n",*x);
}
}
void prin(pstack s)
{
while (s->top>-1) {
printf("--->%d",s->data[s->top]);
s->top--;
}
}
int main()
{
pstack s=init();
int i;
for(int i=1;i<=5;i++)
push(s,i);
pop(s,&i);
pop(s,&i);
pop(s,&i);
pop(s,&i);
prin(s);
return 0;
}
顺序栈(非链式栈)
最新推荐文章于 2024-07-24 16:46:42 发布