/*********************************************************************** * linkedlist.h * * Header file for a simple inplementation of an expandable queue * * Written by Paul Bonamy - 23 May 2010 * Rewritten in pure C - 20 July 2010 ************************************************************************/ #ifndef EQUEUE_H #define EQUEUE_H /*********************************************************************** * C doesn't understand classes, so we'll use a struct for the node * * We normally need to refer to a struct specifically as * 'struct Node', rather than just as 'Node'. The typedef allows us * to refer to a Node as a 'NODE', which requires rather less typing. ***********************************************************************/ typedef struct Node { // note that we aren't explicitly declaring these public // struct members are always automatically public int value; // value stored in the list struct Node * next; // next node in the list. set to 0 if last node struct Node * prev; // previous node in the list, 0 if first node // note that there's no longer a constructor. We'll have // to set up left = right = 0 on our own from here on out. } NODE; /*********************************************************************** * The EQueue class used to live here. We can't use classes in C, * so we'll have to make do with a struct to manage the head and * tail pointers and a bunch of global functions. * * Note, however, that I'm leaving function prototypes here * * Passing around a pointer to an equeue seems a little ugly, but * it means we can have as many equeues as we want. It also means * we don't need global variables, which is always a plus ***********************************************************************/ typedef struct EQueue { NODE * head; // address of first node in the list NODE * tail; // address of last node in the list } EQUEUE; void equeue_init(EQUEUE *queue); // initialize the given queue void equeue_cleanup(EQUEUE *queue); // empty out the given queue int equeue_enqueue(EQUEUE *queue, int v); // insert v into queue int equeue_dequeue(EQUEUE *queue, int *v); // pull a value from queue into v void equeue_empty(EQUEUE *queue); // delete all values in queue #endif