Advertisement
fqrmix

Untitled

Dec 25th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #define STACK_OVERFLOW -100
  2. #define STACK_UNDERFLOW -101
  3. #define STACKSIZE 10
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. struct Stack {
  9.     float Array[STACKSIZE];
  10.     int size;
  11. };
  12.  
  13. void push(Stack *stack, float value);
  14. void printStackValue(int value);
  15. void printStack(const Stack *stack);
  16.  
  17.  
  18. int main()
  19. {
  20.     Stack Stack;
  21.     Stack.size = 0;
  22.     push(&Stack, 3);
  23.     push(&Stack, 5);
  24.     push(&Stack, 7);
  25.     printStack(&Stack);
  26.     return 0;
  27. }
  28.  
  29. void printStackValue(int value) {
  30.     printf("%d", value);
  31. }
  32.  
  33. void printStack(const Stack *stack) {
  34.     int i;
  35.     int len = stack->size - 1;
  36.     printf("stack size = %d > \n", stack->size);
  37.     for (i = 0; i < len; i++) {
  38.         printStackValue(stack->Array[i]);
  39.         printf(" | ");
  40.     }
  41.     if (stack->size != 0) {
  42.         printStackValue(stack->Array[i]);
  43.     }
  44.     printf("\n");
  45. }
  46.  
  47. void push(Stack *stack, float value)
  48. {
  49.     if (stack->size >= STACKSIZE)
  50.         exit(STACK_OVERFLOW);
  51.     stack->Array[stack->size] = value;
  52.     stack->size++;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement