aaronvan

stack.c

Aug 29th, 2020
2,726
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* stack.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. #include "stack.h"
  7.  
  8. void push(int number, stack **stk_ptr) {
  9.     stack *stk, *tmp;
  10.     stk = *stk_ptr;
  11.     tmp = malloc(sizeof(stack));
  12.     tmp->number = number;
  13.     tmp->next = stk;
  14.     stk = tmp;
  15.     *stk_ptr = stk;
  16. }
  17.  
  18. int pop(stack **stk_ptr) {
  19.     int number;
  20.     stack *stk, *tmp;
  21.     stk = *stk_ptr;
  22.     tmp = stk;
  23.     number = tmp->number;
  24.     stk = stk->next;
  25.     free(tmp);
  26.     *stk_ptr = stk;
  27.     return number;
  28.  }        
RAW Paste Data