| 1 |
/************************************************************************** |
| 2 |
* This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is * |
| 3 |
* provided by Jonathan and Jovehacks without charge and without * |
| 4 |
* warranty. You may copy, modify, and/or distribute JOVE, provided that * |
| 5 |
* this notice is included in all the source files and documentation. * |
| 6 |
**************************************************************************/ |
| 7 |
|
| 8 |
#include "jove.h" |
| 9 |
#include "list.h" |
| 10 |
|
| 11 |
private List * |
| 12 |
list_new(void) |
| 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 |
void * |
| 24 |
list_push(List **list, void *element) |
| 25 |
{ |
| 26 |
List *new; |
| 27 |
|
| 28 |
new = list_new(); |
| 29 |
new->cdr = *list; |
| 30 |
new->car = element; |
| 31 |
*list = new; |
| 32 |
return element; |
| 33 |
} |
| 34 |
|
| 35 |
void * |
| 36 |
list_pop(List **list) |
| 37 |
{ |
| 38 |
List *cell = *list; |
| 39 |
void *element; |
| 40 |
|
| 41 |
if (cell == NULL) |
| 42 |
return NULL; |
| 43 |
|
| 44 |
element = cell->car; |
| 45 |
*list = cell->cdr; |
| 46 |
free(cell); |
| 47 |
return element; |
| 48 |
} |