Implementation of the chain storage structure of the queue 2-calculate the number of elements at the beginning and end of the queue for viewing the queue
// 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; // The Node data struct Node * next; // record the next Node address} Node; // define the Queue data type typedef struct {Node * head; // header pointer} Queue; // output int pop (Queue * pq ); // view the first element int get_head (Queue * pq); // view the last element int get_tail (Queue * pq ); // calculate the int size (Queue * pq) of all elements in the Queue); Int main (void) {return 0;} // departure int pop (Queue * pq) {if (empty (pq) {return-1 ;} // find a replacement Node for the header pointer * p = pq-> head; p-> head = p-> next; // store the node data to be released int temp = p-> data; free (p); p = NULL; // return the released node data return temp ;} // view the first element int get_head (Queue * pq) {if (empty (pq) {return-1; // use-1 to indicate an error} return pq-> head-> data;} // view the team end element int get_tail (Queue * pq) {// The queue is empty. if (empty (pq) {return-1;} // The queue is not empty. // substitute Node * p = pq-> h Ead; // move the pointer cyclically and locate the last node while (p-> next! = NULL) {p = p-> next;} // return the end node data return p-> data;} // calculate the number of all elements in the Queue int size (Queue * pq) {int cnt = 0; Node * p = pq-> head; while (p! = NULL) {cnt ++; p = p-> next;} return cnt ;}