QUEUE
IMPLEMENTATION:
front=rear=-1;
int queue[MAX];
void enqueue(int element)
{
if(rear==(MAX-1))
{
printf(“Queue
is full!\n”);
return;
}
else if(rear=-1 && front=-1)
{
front++;
rear++;
queue[rear]=element;
}
else
{
rear++;
queue[rear]=element;
}
}
int dequeue()
{
int
data;
if(front==-1)
{
printf(“Queue
is empty!\n”);
return;
}
else if(front==rear)
{
data=queue[front];
front=rear=-1;
return
data;
}
else
{
data=queue[front];
front++;
return data;
}
}
No comments:
Post a Comment