1 #include <stdio.h>
2 /*
3 题目:栈的自实现
4 思路:栈的典型特点就是先进后出(FILO),或是后进先出(LIFO)。主要接口操作,主要有四类,分别是,判空,判满,压栈,出栈
5 */
6 //声明栈类型
7 struct stack
8 {
9 char arr[152];
10 int top;//计数
11 };
12
13 struct stack stack = {{0},0};
14
15 int isfull()//判满
16 {
17 return stack.top == 152;
18 }
19 void push(int a)//压栈
20 {
21 stack.arr[stack.top] = a;
22 stack.top++;
23 }
24 int isempty()//判空
25 {
26 return stack.top == 0;
27 }
28 char pop()//出栈
29 {
30 stack.top--;
31 return stack.arr[stack.top];
32 }
33 int main(void)
34 {
35 if(!isfull())
36 push('a');
37 if(!isfull())
38 push('b');
39 if(!isfull())
40 push('c');
41 while(!isempty())
42 putchar(pop());
43
44
45 return 0;
46 }