C-Language simple queue (array queue)

Source: Internet
Author: User

//a simple queue#include<stdio.h>#include<stdlib.h>#definedatatype int#defineN 10//defining the queue structure bodystructqueue{intFront//Team Head    intEndLine//End of TeamDataType data[n];//Data};typedefstructqueue queue; Queue Myqueue= {0,0, {0 } };//Initialize QueuevoidInitqueue (Queue *p);//QueuevoidEnQueue (Queue *Pque, datatype data);//out TeamvoidDeQueue (Queue *pque);//Traverse QueuevoidPrintfqueue (Queue *pque);//array queues can only be used once, and must be initialized before they can continue to be usedvoidMain () {Queue*pque =(Queue *)malloc(sizeof(Queue));    Initqueue (Pque); //Insert QueueEnQueue (Pque,1); EnQueue (Pque,2); EnQueue (Pque,8); EnQueue (Pque,3); EnQueue (Pque,7); //print queuePrintfqueue (Pque); //out TeamDeQueue (Pque); //print queuePrintfqueue (Pque);    DeQueue (Pque); //print queuePrintfqueue (Pque); System ("Pause");}//Initialize QueuevoidInitqueue (Queue *Pque) {Pque->front = Pque->endline =0;//Empty Queue}//QueuevoidEnQueue (Queue *Pque,datatype data) {    //determine if the queue overflows    if(pque->endline<N) {//determine if the queue is empty        if(Pque->front = = pque->endline)//team head and tail coincide indicate no element        {            //Initialize QueueInitqueue (Pque); } pque->data[pque->endline] =data; Pque->endline + =1; }    Else{        return; }    }//out TeamvoidDeQueue (Queue *Pque) {    //determine if the queue is empty    if(Pque->front = = pque->endline) {        //queue is empty        return; }    Else{        //Pop the last one directlyprintf"the element that pops up is%d\n", pque->data[pque->Front]); Pque->front+=1; }}//Traverse QueuevoidPrintfqueue (Queue *Pque) {     for(inti = pque->front; I < pque->endline; i++) {printf ("%d\n", pque->Data[i]); }}

C-Language simple queue (array 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.