Implementation of the queue chain Storage Structure 1 -- create and destroy to determine whether the queue is full or empty

Source: Internet
Author: User

Implementation of the queue chain Storage Structure 1 -- create and destroy to determine whether the queue is full or empty

// Filename: list_queue.c // Author: LupingChen/Data: 2015.05.30 // Content: create \ destory \ full \ empty \ push # include <stadio. h> # include <stdlib. h> // define the Node data type typedef struct Node {int data; // data struct Node * next; // record the next Node address} Node; // define the Queue data type typedef struct {Node * head; // header pointer} Queue; // determine whether the Queue is full int full (Queue * pq ); // determine whether the Queue is empty int empty (Queue * pq); // enter the Queue void push (Queue * pq, data); // traverse void travel (Queue * pq); I Nt main () {// create, the system destroys the Queue queue; queue. head = NULL; return 0;} // determines whether the Queue is full int full (Queue * pq) {return 0 ;} // determine whether the Queue is empty int empty (Queue * pq) {return NULL = pq-> head;} // Queue void push (Queue * pq, data) {// create Node * pn = (Node *) malloc (sizeof (Node); pn-> data = data; pn-> next = NULL; // mount the Node // empty queue Mount if (empty) {pq-> head = pn;} // non-empty queue Mount Node * p = pq-> head; while (p-> next! = NULL) {p = p-> next;} p-> next = pn;} // traverse void travel (Queue * pq) {printf ("Queue metadata: "); Node * p = pq-> head; while (p! = NULL) {printf ("% d", p-> data); p = p-> next;} printf ("\ n ");}

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.