You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
657 B

  1. #include "stack.h"
  2. #define STACK_TYPE size_t
  3. #ifdef STACK_TYPE
  4. int stack_push(struct stack_cell_t** l, STACK_TYPE elt) {
  5. if(!*l || (*l)->sommet <= 0 ) {
  6. struct stack_cell_t* tmp = *l;
  7. (*l) = (struct stack_cell_t*) malloc(sizeof(struct stack_cell_t));
  8. if(!*l)
  9. return 0;
  10. (*l)->next=tmp;
  11. (*l)->sommet=STACK_TAB_SIZE;
  12. }
  13. (*l)->tab[--((*l)->sommet)]=elt;
  14. return 1;
  15. }
  16. STACK_TYPE* stack_pop(struct stack_cell_t** l) {
  17. if(!*l)
  18. return NULL;
  19. STACK_TYPE* tmp = & ((*l)->tab[((*l)->sommet)++]);
  20. if((*l)->sommet >= STACK_TAB_SIZE) {
  21. struct stack_cell_t* tmp = *l;
  22. (*l) = (*l)->next;
  23. free(tmp);
  24. }
  25. return tmp;
  26. }
  27. #endif