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.
 
 
 
 

28 lines
657 B

#include "stack.h"
#define STACK_TYPE size_t
#ifdef STACK_TYPE
int stack_push(struct stack_cell_t** l, STACK_TYPE elt) {
if(!*l || (*l)->sommet <= 0 ) {
struct stack_cell_t* tmp = *l;
(*l) = (struct stack_cell_t*) malloc(sizeof(struct stack_cell_t));
if(!*l)
return 0;
(*l)->next=tmp;
(*l)->sommet=STACK_TAB_SIZE;
}
(*l)->tab[--((*l)->sommet)]=elt;
return 1;
}
STACK_TYPE* stack_pop(struct stack_cell_t** l) {
if(!*l)
return NULL;
STACK_TYPE* tmp = & ((*l)->tab[((*l)->sommet)++]);
if((*l)->sommet >= STACK_TAB_SIZE) {
struct stack_cell_t* tmp = *l;
(*l) = (*l)->next;
free(tmp);
}
return tmp;
}
#endif