home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / colag.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-12  |  2.1 KB  |  77 lines

  1. // COLAG.H
  2. // (C) Anubis Software Agosto 1995
  3.  
  4. #ifndef COLAG.H
  5. #define COLAG.H
  6.  
  7. // --------------------------------------+
  8. // Librerias de BorlandC ++              |
  9. // --------------------------------------+
  10. #include <alloc.h>
  11.  
  12. // --------------------------------------+
  13. // Librerias de Anubis Software          |
  14. // --------------------------------------+
  15. #include "generica.h"
  16.  
  17. // --------------------------------------+
  18. // Constantes definidas en la librería   |
  19. // --------------------------------------+
  20. #define COLAG_TODO_OK                  0
  21. #define COLAG_MEMORIA_INSUFICIENTE    1
  22.  
  23. // --------------------------------------+
  24. // Tipos predefinidos por la libreria    |
  25. // --------------------------------------+
  26. typedef struct {
  27.     TipoElemento *Inicio;
  28.     TipoElemento *Fin;
  29. } ColaGenerica;
  30.  
  31. // --------------------------------------+
  32. // Macros de la librería                 |
  33. // --------------------------------------+
  34. #define ColaGenericaVacia(x)    ((*x).Fin == NULL)
  35. #define ColaGenericaTope(x)     ((*((*x).Fin)).Apuntador)
  36.  
  37. // --------------------------------------+
  38. // Funciones de la libreria              |
  39. // --------------------------------------+
  40. void ColaGenericaAnula( ColaGenerica *cola)
  41. {
  42.     (*cola).Inicio = NULL;
  43.     (*cola).Fin = NULL;
  44. }// end ColaGenericaAnula
  45.  
  46. void ColaGenericaMete(ColaGenerica *cola, void *apuntador)
  47. {
  48.     TipoElemento *elem;
  49.     elem= (TipoElemento *) malloc(sizeof(TipoElemento));
  50.     if( elem != NULL)  {
  51.         (*elem).Apuntador = apuntador;
  52.         (*elem).Siguiente = NULL;
  53.         if( ColaGenericaVacia(cola))  {
  54.             (*cola).Fin = elem;
  55.             (*cola).Inicio = elem;
  56.         }  else  {
  57.             (*((*cola).Inicio)).Siguiente = elem;
  58.             (*cola).Inicio= elem;
  59.         }// end if
  60.         return(COLAG_TODO_OK);
  61.     }  else
  62.         return( COLAG_MEMORIA_INSUFICIENTE);
  63. }// end ColaGenericaMete
  64.  
  65. void *ColaGenericaSaca(ColaGenerica *cola)
  66. {
  67.     TipoElemento *elem= (*cola).Fin;
  68.     void *apuntador = (*elem).Apuntador;
  69.     (*cola).Fin = (*elem).Siguiente;
  70.     if ( (*cola).Fin == NULL)
  71.         (*cola).Inicio = NULL;
  72.     free(elem);
  73.     return(apuntador);
  74. }// end ColaGenericaSaca
  75.  
  76.  
  77. #endif