Large concurrent Data queue

Source: Internet
Author: User

Graphic 650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/610439/201601/ 610439-20160130151820974-712348880.png "width=" 759 "height=" 634 "alt=" 610439-20160130151820974-712348880.png "/ >

#include <stdio.h>

#include <stdlib.h>

#include <memory.h>

#define N 100

#define MYTYPE INT

struct Myqueue

{

MyType data[n];//Array Storage queue

int front;//Poop

int rear;//Eat Something

};


typedef struct MYQUEUE MyQ;

Initialization

void init (MyQ *p)

{

P->front = p->rear = 0;

memset (p->data,0,sizeof (MyType) *n);


}

void print (MyQ *p)

{


if (IsEmpty (p) ==1)

{

return 0;

}else{

int i;

for (i=p->front;i<p->rear;i++)

{

printf ("%d", p->data[i]);

}

}

}

int Isfull (MyQ *p)

{

if (p->rear = = N)

{

return 1;

}else

{

return 0;

}

}

int IsEmpty (MyQ *p)

{

if (p->front==p->rear)

{

return 1;

}else{

return 0;

}

}

void EnQ (MyQ *p,mytype insertdata)

{

if (Isfull (p) ==1)

{

Return

}else{

P->data[p->rear] = InsertData;

p->rear+=1;

}

}

MyType DeQ (MyQ *p)

{

if (IsEmpty (p) ==1)

{

return 0;

}

int index = (p->rear)-(P->front);

if (index==1)

{

Return p->data[0];

}else{

int i;

printf ("\ n index=%d", index);

for (i=0;i<index-1;i++)

{

P->data[i] = p->data[i+1];

}

--p->rear;


}

printf ("\ n index=%d", p->rear);

Return p->data[p->rear];

}

MyType Array_shift (MyQ *p)

{

if (IsEmpty (p) ==1)

{


Exit (1);

}

else{

int num = p->front;


Free (P->data[num]);

Return p->data[p->front++];

}


}

MyType Array_pop (MyQ *p)

{

if (IsEmpty (p) ==1)

{


return 0;

}else{


int num = p->rear;

Free (P->data[num]);

Return p->data[--p->rear];

}



}


void Main ()

{


MyQ my1;//Create struct body

Init (&MY1);

EnQ (&my1,1);

EnQ (&my1,2);

EnQ (&my1,3);

EnQ (&my1,4);



printf ("\npop =%d", Array_pop (&my1));

printf ("\nnumber=%d", Array_shift (&my1));

printf ("\ n one=%d", Array_shift (&my1));

printf ("\ n =%d", Array_shift (&my1));


printf ("\ n three =%d", Array_shift (&my1));


System ("pause");

}









Large concurrent Data 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.