home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / baseline / jove-4.14.6.lha / jove-4.14.6 / list.c < prev    next >
C/C++ Source or Header  |  1992-01-10  |  1KB  |  53 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7.  
  8. #include "jove.h"
  9. #include "list.h"
  10.  
  11. private List *
  12. list_new()
  13. {
  14.     List    *new;
  15.  
  16.     new = (List *) emalloc(sizeof (List));
  17.     new->car = NULL;
  18.     return new;
  19. }
  20.  
  21. /* push an object to the beginning of list */
  22.  
  23. UnivPtr
  24. list_push(list, element)
  25. register List    **list;
  26. UnivPtr element;
  27. {
  28.     List    *new;
  29.  
  30.     new = list_new();
  31.     new->cdr = *list;
  32.     new->car = element;
  33.     *list = new;
  34.     return element;
  35. }
  36.  
  37. UnivPtr
  38. list_pop(list)
  39. List    **list;
  40. {
  41.     List    *cell;
  42.     UnivPtr    element;
  43.  
  44.     if (*list == NULL)
  45.         return NULL;
  46.     cell = *list;
  47.     element = cell->car;
  48.     free((UnivPtr) cell);
  49.     *list = (*list)->cdr;
  50.  
  51.     return element;
  52. }
  53.