Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //#include <conio.h>
  4.  
  5. #define N 101
  6. #define SMAX 256
  7.  
  8. // typedef int StackElemType;
  9.  
  10. typedef char String[SMAX];
  11. typedef int BinaryTreeDataType;
  12. typedef struct binarytreenode BinaryTreeNode;
  13. struct binarytreenode
  14. {
  15. BinaryTreeNode* LSON;
  16. BinaryTreeDataType DATA;
  17. BinaryTreeNode* RSON;
  18. };
  19. struct stackelemtype
  20. {
  21. BinaryTreeNode* address;
  22. char tag;
  23. };
  24. typedef struct stackelemtype StackElemType;
  25.  
  26. struct stack
  27. {
  28. int top;
  29. StackElemType Stack[N];
  30. };
  31. typedef struct stack Stack;
  32.  
  33. void InitStack(Stack *S)
  34. {
  35. S->top = 0;
  36. }
  37.  
  38. int IsEmptyStack(Stack *S)
  39. {
  40. return (S->top == 0);
  41. }
  42.  
  43. void StackOverflow(void)
  44. {
  45. printf("Stack overflow detected.\n");
  46. exit(1);
  47. }
  48.  
  49. void StackUnderflow(void)
  50. {
  51. printf("Stack underflow detected.\n");
  52. exit(1);
  53. }
  54.  
  55. void PUSH (Stack *S, StackElemType x)
  56. {
  57. if (S->top == N) StackOverflow();
  58. else
  59. {
  60. ++S->top;
  61. S->Stack[S->top] = x;
  62. }
  63. }
  64.  
  65. void POP (Stack *S, StackElemType *x)
  66. {
  67. if (S->top == 0) StackUnderflow();
  68. else
  69. {
  70. *x = S->Stack[S->top];
  71. --S->top;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement