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