Glaas2

Pila.c

Oct 7th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include "Pila.h"
  3.  
  4. void INIT(pila *p)
  5. {
  6. *p==NULL;
  7. }
  8.  
  9. nodo TOP(pila p)
  10. {
  11.  nodo AUX;
  12.  AUX=*p;
  13.  AUX.sig=NULL;
  14.  return AUX;    
  15. }
  16.  
  17.  
  18. msg PUSH(pila *p, nodo n)
  19. {
  20.  pila temp;
  21.  temp=malloc(sizeof(nodo));
  22.  if(!temp)
  23.   return NO_MEMORY;
  24.  *temp= n;
  25.  temp->sig=*p;
  26.  *p=temp;
  27.  return OK;  
  28. }
  29.  
  30. nodo POP(pila *p)
  31. {
  32.  nodo copia;
  33.  pila AUX;
  34.  copia = **p;
  35.  copia.sig=NULL;
  36.  AUX=(*p)->sig;
  37.  free(*p);
  38.  *p=AUX;
  39.  return copia;    
  40. }
  41.  
  42.  
  43. boolean EMPTY(pila p)
  44. {
  45.  if(p==NULL)
  46.   return TRUE;
  47.  return FALSE;      
  48. }
  49.  
  50.  
  51. void PURGE(pila *p)
  52. {
  53.  while(!EMPTY(*p))
  54.  {
  55.   POP(p);
  56.  }    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment