Chained Storage---chain list implementation (with head node)

Source: Internet
Author: User

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

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.