- 1#include 2 3 using namespace std;
- 4 5 typedef struct Stack 6 {
- 7 char space[1024];
- 8 int top;
- 9
- }
- Stack;
- 10 void init(Stack * s) 11 {
- 12 s - >top = 0;
- 13 memset(s - >space, 0, 1024);
- 14
- }
- 15 int isEmpty(Stack * s) 16 {
- 17
- return s - >top == 0;
- 18
- }
- 19 int isFull(Stack * s) 20 {
- 21
- return s - >top == 1024;
- 22
- }
- 23 24 char pop(Stack * s) 25 {
- 26
- return s - >space[--(s - >top)];
- 27
- }
- 28 char push(Stack * s, char c) 29 {
- 30
- return s - >space[s - >top++] = c;
- 31
- }
- 32 int main() 33 {
- 34 35 Stack st;
- 36 init( & st);
- 37
- if (!isFull( & st)) 38 {
- 39 push( & st, 'g');
- 40
- }
- 41
- if (!isFull( & st)) 42 {
- 43 push( & st, 't');
- 44
- }
- 45
- if (!isFull( & st)) 46 {
- 47 push( & st, 'n');
- 48
- }
- 49
- if (!isFull( & st)) 50 {
- 51 push( & st, 'h');
- 52
- }
- 53
- if (!isFull( & st)) 54 {
- 55 push( & st, 'r');
- 56
- }
- 57
- while (!isEmpty( & st)) 58 {
- 59 cout < endl;
- 60
- }
- 61
- return 1;
- 62
- }
来源: