I
# include
queue is importnant in people live to organize the cocity, this code i
wnat to share with others
and recieve comment about, with all of my thanks
# include<stdio.h>
# define MAX 100
typedef int itemtype;
typedef struct queue{
itemtype item[MAX];
int f;
int r;
}Queue;
void clear(Queue *q)
{
q->r=0;
q->f=0;
}
void enq(Queue *q,itemtype x)
{
q->r=(q->r+1)%MAX;
q->item[q->r]=x;
}
void deq(Queue *q,itemtype *x)
{
q->f=(q->f+1)%MAX;
*x=q->item[q->f];
}
int empty(Queue *q)
{
return (q->r==q->f);
}
int full(Queue *q)
{
return ((q->r+1)%MAX==q->f);
}
main()
{
int i;
Queue q1;
clear(&q1);
for(i=0;i<10;i++)
if (!full(&q1)) enq(&q1,i);
while(!empty(&q1))
{
deq(&q1,&i);
printf("%d\n",i);
}
}
wnat to share with others
and recieve comment about, with all of my thanks
# include<stdio.h>
# define MAX 100
typedef int itemtype;
typedef struct queue{
itemtype item[MAX];
int f;
int r;
}Queue;
void clear(Queue *q)
{
q->r=0;
q->f=0;
}
void enq(Queue *q,itemtype x)
{
q->r=(q->r+1)%MAX;
q->item[q->r]=x;
}
void deq(Queue *q,itemtype *x)
{
q->f=(q->f+1)%MAX;
*x=q->item[q->f];
}
int empty(Queue *q)
{
return (q->r==q->f);
}
int full(Queue *q)
{
return ((q->r+1)%MAX==q->f);
}
main()
{
int i;
Queue q1;
clear(&q1);
for(i=0;i<10;i++)
if (!full(&q1)) enq(&q1,i);
while(!empty(&q1))
{
deq(&q1,&i);
printf("%d\n",i);
}
}