/ * Author: Avalon QQ: 1243128 Date: 05-10-04 21:18 Description: generic queue * /
#ifndef avalon_queue_h # define avalon_queue_h
#ifndef ava_bool # define ava_bool # define true 1 # define false 0typedef int bool; #ENDIF
Typedef struct link * lastile;
EXTERN LHANDLE INTQUEUE (SIZE_T TYPE); / * Construction * / Extern Bool QueueemPty (LHANDLE q); / * EMPTY? * / EXTERN INT QueueLength (LHANDLE q); / * length * / extern bool gethead (LHANDLE q, void * ELEM ); * If the queue is not empty, the Copy team head element, and return true * / extern bool enqueue (LHANDLE q, void * elem); / * Insert element ELEM is a new tail element * / extern Bool Dequeue LHANDLE Q, VOID * ELEM); / * If ELEM is not empty, the deleted head knot value is assigned to ELEM, return true * / extern bool clearqueue (LHANDE Q); / * Empty * / Extern Bool DestroyQueue ( LHANDLE * Q); / * Destroy * / # Endif
//
///
/ * Author: avalon QQ: 1243128 Date: 05-10-04 21:18 Description: generic queue * / # include
#ifndef ava_bool # define ava_bool # define true 1 # define false 0typedef int bool; #ENDIF
TypedEf struct node {void * data; / * Data pointer * / struct node * next; / * Next Node * /} node, * nhandle
Typedef struct; / * head pointer * / nhandle rest; / * tail pointer * / int size; / * length * / size_t type;} link, * LHANDLE; / * internal function * / static nhandle allocnode (LHANDLE S, VOID * ELEM) {/ * Assign Node * / NHANDLE NODE_TEMP = (NHANDLE) Malloc (SizeOf (Node)); void * data_temp; assert (null! = Node_temp); assert (null! = S); assert NULL! = ELEM); DATA_TEMP = Malloc (S-> Type); assert (null! = Data_temp); memcpy (data_temp, elem, s-> type); / * Copy data * / node_temp-> data = data_temp; / * MEMBER DATA assignment * / return node_temp;} static bool freenode (nhandle * node) {/ * release node * / free ((* node) -> data); free (* node); return true;} / * External Function * / extern LHANDLE INTQUE (SIZE_T TYPE) {/ * Construction * / LHANDLE TEMP = (LHANDLE) Malloc (SIZEOF (LINK)); Assert (NULL! = Temp); Temp-> Front = Temp-> Rear = NULL; Temp-> size = 0; TEMP-> TYPE = Type; Return Temp;} Extern Bool Queueempty (LHANDLE q) {/ * EMPTY? * / assert (null! = q); return (0 == q-> size) True: false;} Extern Int Quelength (LHANDLE q) {/ * length * / Assert (null! = Q); Return Q-> size;} extern bool gethead (LHANDE Q, VOID * ELEM) {/ * If the queue is not empty, the Copy header element, and return true * / assert (null ! = q); assert (null! = ELEM); if (null == q-> front) Return False; memcpy (elem, q-> front-> data, q-> type); return true;} Extern Bool Enqueue (LHANDE Q, VOID * ELEM) {/ * Insert Element ELEM is a new team tail element * / nhandle Temp; assert (null! = Q); assert (null! = Elem); Temp = AllocNode (q, elem) ; / ** / if ((q-> size) ! = 0) {/ * length plus 1 * / Q-> Rear-> next = Temp; Q-> Rear = Q-> Rear-> next; } Else {q-> front = Q-> REAR = TEMP;