Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //#include <conio.h>
- #define N 101
- #define SMAX 256
- // typedef int StackElemType;
- typedef char String[SMAX];
- typedef int BinaryTreeDataType;
- typedef struct binarytreenode BinaryTreeNode;
- struct binarytreenode
- {
- BinaryTreeNode* LSON;
- BinaryTreeDataType DATA;
- BinaryTreeNode* RSON;
- };
- struct stackelemtype
- {
- BinaryTreeNode* address;
- char tag;
- };
- typedef struct stackelemtype StackElemType;
- struct stack
- {
- int top;
- StackElemType Stack[N];
- };
- typedef struct stack Stack;
- void InitStack(Stack *S)
- {
- S->top = 0;
- }
- int IsEmptyStack(Stack *S)
- {
- return (S->top == 0);
- }
- void StackOverflow(void)
- {
- printf("Stack overflow detected.\n");
- exit(1);
- }
- void StackUnderflow(void)
- {
- printf("Stack underflow detected.\n");
- exit(1);
- }
- void PUSH (Stack *S, StackElemType x)
- {
- if (S->top == N) StackOverflow();
- else
- {
- ++S->top;
- S->Stack[S->top] = x;
- }
- }
- void POP (Stack *S, StackElemType *x)
- {
- if (S->top == 0) StackUnderflow();
- else
- {
- *x = S->Stack[S->top];
- --S->top;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement