#define MAXQUEUE 5
typedef struct {
char data[MAXQUEUE];
int rear;
int front;
int counter;
}QUEUE;
void initial(QUEUE *q);
int enqueue(QUEUE *q,char item);
int dequeue(QUEUE *q,char *ret);
void initial(QUEUE *q){
q->front=-1;
q->rear=-1;
q->counter=0;
}
int enqueue(QUEUE *q,char item)
{
if (q->counter == MAXQUEUE){
printf("FULL QUEUE !!! \n");
return 0;
}
else
{
q->counter++;
q->rear=(q->rear+1)%MAXQUEUE;
q->data[q->rear] = item;
printf("\t enqueue <- %c \n",q->data[q->rear]);
}
return 1;
}
No comments:
Post a Comment