/*chained storage for queues*//*With no header*/structNode;structLinkqueue;typedefstructNode *Ptrtonode;typedefstructLinkqueue *Ptrtorf;structnode{ElementType X; Ptrtonode Next;};structlinkqueue{Ptrtonode Rear; Ptrtonode Front;};intIsEmpty (Ptrtorf ptrq) {returnPtrq->front = =NULL;} Elementype Deleq (Ptrtorf ptrq) {Ptrtonode Tmpcell; ElementType X; if(IsEmpty (PTRQ)) {Error ("queue is empty"); retutn; } Tmpcell= ptrq->Front; X= tmpcell->Element; if(Ptrq->front = = ptrq->rear) {PTRQ->front =NULL; PTRQ->rear =NULL; } ElsePTRQ->front = tmpcell->Next; Free(Tmpcell); returnX;}voidADDQ (Ptrtorf ptrq) {Ptrtonode Tmpcell; Tmpcell=malloc(sizeof(structNode)); if(Tmocell = =NULL) Error ("Out if space"); Tmpcell->next = =NULL; Tmpcell->element =X; if( ! (Isempy (PTRQ))) {//when the queue is non-empty, only rear is moved.Ptrq->rear->next =Tmpcell; PTRQ->rear =Tmpcell; } ElsePTRQ->rear = Ptr->front = Tmpcell;//the chain store of the queue, front and rear all point to one place, only to indicate that there is an element, if all points to null means null}View Code
Chain-Store---chain list implementation of queues