# include
#define MAX 5
#define TRUE 1
#define FALSE 0
#define ERROR -1
struct qinfo{
int front,rear;
int noele;
int qelement[MAX];
};
typedef struct qinfo queue;
void create(),insert_queue();
int isfull(),isfull(),delete_queue();
void create(queue *q)
{
q->front=-1;
q->rear=-1;
q->noele=0;
return;
}
int isempty(queue *q)
{
if(q->noele == 0)
return(TRUE);
else
return(FALSE);
}
int isfull(queue *q)
{
if(q->noele == MAX)
return(TRUE);
else
return(FALSE);
}
void insert_queue(queue *q,int item)
{
char stop;
if(isfull(q))
printf("Queue is full \n");
else
{
if(isempty(q))
{
create(q);
q->front++;
q->rear++;
}
else
if(q->rear < (MAX - 1) || q->rear < (q->front - 1))
q->rear++;
else
if(q->rear == (MAX - 1) && q->noele <>
q->rear=0;
q->qelement[q->rear]=item;
q->noele++;
}
return;
}
int delete_queue(queue *q)
{
int data;
if(isempty(q))
{
printf("Queue is empty!!!\n");
return(ERROR);
}
else
{
data=q->qelement[q->front];
if(q->front == (MAX - 1))
q->front=0;
else
q->front++;
q->noele--;
if(isempty(q))
create(q);
return(data);
}
}
No comments:
Post a Comment