From biermann@mrl.nyu.edu Thu Apr 1 18:35:18 1999 Date: Thu, 1 Apr 1999 18:33:01 -0500 (EST) From: Henning Biermann #include #include typedef int ElementType; typedef struct NodeStruct { ElementType elem; struct NodeStruct *next; } NodeType; NodeType* first = NULL; NodeType* last = NULL; int emptyQueue() { return (first == NULL); } void enqueue(ElementType elem) { NodeType* tmpNode; tmpNode = malloc(sizeof(NodeType)); tmpNode->elem = elem; tmpNode->next = NULL; if (first == NULL) { last = first = tmpNode; } else { last->next = tmpNode; last = tmpNode; } } ElementType dequeue() { NodeType* tmpNode; tmpNode = first; first = first->next; return tmpNode->elem; } int main() { int i; int j; for (i = 0; i < 10; i++) enqueue(i); for (i = 0; i < 5; i++) dequeue(i); for (i = 10; i < 15; i++) enqueue(i); while(!emptyQueue()) { i = dequeue(); printf("dequeued:\t%d\n",i); } }