/*chained storage for queues*//*With header*//*With no typedef*/structnode{ElementType Ele; structNode *Next;};structlinq{structNode *Rear; structNode *Front;};structLinQ *Createq (void ){ structLinQ *Ptr; structNode *header; Ptr=malloc(sizeof(structLinQ)); if(Ptr = =NULL) Error ("Out of space"); Header=malloc(sizeof(structNode)); if(Header = =NULL) Error ("Out of space"); Header->next =NULL; Ptr->front = Ptr->rear =header;}voidADDQ (structLinQ *PTRQ, ElementType X) { structNode *Ptr; Ptr=malloc(sizeof(structNode)); if(Ptr = =NULL) Error ("Out of space"); Ptr->ele =X; Ptr->next =NULL; PTRQ->rear->next =Ptr; PTRQ->rear =Ptr;}intIsEmpty (structLinQ *PTRQ) { returnPtrq->front->next = =NULL;} Elementtypedeleteq (structLinQ *PTRQ) { structNode *Tmpcell; if(IsEmpty (PTRQ)) Error ("Empty Queue"); Tmpcell= ptrq->front->Next; PTRQ->front->next = tmpcell->Next; Free(Tmpcell);}
View Code
Createq is designed to create a LINQ structure where front and rear both point to the header of the head node
At the head node, next is set to NULL, which is available when judging if the team is empty.
Front always refers to the head node.
Next of the new node must be changed to NULL.
Conclusion: It can be used in the place of the TypeDef, can use the place of the head knot.
Chained Storage---chain list implementation (with head node)