Résultat du TP en C sur Forth
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.

pileInt.c 960B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "pileInt.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. void initPileI( struct PileInt* p ) {
  5. p->height = 0;
  6. p->l = NULL;
  7. }
  8. void pushPileI( struct PileInt* p, programPointer i ) {
  9. struct ListInt* aux = p->l;
  10. p->l = (struct ListInt*)malloc(sizeof(struct ListInt));
  11. if (p->l == NULL) {
  12. fprintf(stderr, "Error: Could not allocate memory for the next cell on the stack");
  13. return;
  14. }
  15. p->l->next = aux;
  16. p->l->i = i;
  17. ++(p->height);
  18. }
  19. int topPileI( struct PileInt* p ) {
  20. if ( p->height == 0 ) {
  21. fprintf(stderr, "Error: The stack has no element, cannot find top");
  22. exit(1);
  23. }
  24. return p->l->i;
  25. }
  26. void popPileI( struct PileInt* p ) {
  27. struct ListInt* aux;
  28. if ( p->height != 0 ) {
  29. --(p->height);
  30. aux = p->l;
  31. p->l = p->l->next;
  32. free(aux);
  33. }
  34. }
  35. void endPileI( struct PileInt* p ) {
  36. while (p->height != 0) {
  37. popPileI(p);
  38. }
  39. }