include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAXSIZE 100
#define ElemType char
typedef struct{
ElemType data[100];
int top;
}stack;
void initStack(stack *s){
s->top=-1;
}
int isEmpty(stack s){
if(s.top==-1){
return 1;
}
return 0;
}
int isFull(stack s){
if(s.top==MAXSIZE-1){
return 1;
}
return 0;
}
void pushStack(stack *s,ElemType ele){
if(!isFull(*s)){
s->data[++s->top] = ele;
}
else{
printf("栈已满\n");
}
}
ElemType popStack(stack *s){
if(!isEmpty(*s)){
return s->data[s->top--];
}
printf("栈为空\n");
}
int getSize(stack s){
return s.top+1;
}
int main(){
stack s;
int i;
initStack(&s);
for(i=0;i<10;i++){
pushStack(&s,i);
}
printf("%d",popStack(&s));
printf("%d",popStack(&s));
printf("%d\n",popStack(&s));
printf("栈是否为空(1为空):%d\n",isEmpty(s));
printf("栈是否满(1为满):%d\n",isFull(s));
printf("栈的深度:%d\n",getSize(s));
}
网友评论