Queue Learning Notes Loop queue

Source: Internet
Author: User

Tag: return

 //Loop Queue//cycqueue.h#define queuemax 15typedef struct {data data[queuemax];   //Queue Array  int head; //team head  int tail; //team tail  }CycQueue; cycqueue *cycqueueinit  () {cycqueue *q;if (q= (cycqueue *) malloc (sizeof (Cycqueue)))  // Request to save queue memory  {q->head = 0;  //Set team header  q->tail = 0; //set tail   Return q;} elsereturn null; //  return to Empty  }void cycqueuefree (cycqueue *q)   //  release queue  {if (q!=null) free (q);} Int cycqueueisempty (CYCQUEUE&NBSP;*Q)   //  whether the queue is empty  {  return   (Q- >head==q->tail)  ;} int cycqueueisfull  (cycqueue *q)  //  queue is full  {return  ((q->tail+1)%queuemax  == q->head)  ;} Int cycqueuein (cycqueue *q,data data)   //  enqueue function {if ((q->tail+1)%queuemax = = q->head) {printf ("queue is full!\n"); RETURN&Nbsp;0;} else{q->tail =  (q->tail+1)%queuemax; //to find the tail number  q->data[q->tail]  =  data;return 1;}  } DATA *CycQueueOut  (cycqueue *q)  //   {if of the queue function (q->head ==  q->tail) {printf ("Queue is empty!\n"); return null; }else{q->head= (q->head+1)%queuemax;return  & (Q->data[q->head]);}   }  int cycqueuelen (cycqueue *q)   //  get Queue Length   {  Int n; n=q->tail-q->head; if (n<0)  n=QUEUEMAX + n; return n;   } data *cycqueuepeek (cycqueue *q)  //  get data  {if for 1th position in queue (q->head== Q->tail) {printf ("Queue already empty!\n"); return null;} else{return & (q->data[(q->head+1)%queuemax]);}}


Queue Learning Notes Loop queue

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.