Chain-Store---chain list implementation of queues

Source: Internet
Author: User

/*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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.