Tuesday, 11 February 2014
#include"std.h"
void enqueue(int item, int *front, int *rear, int *queue, int SIZE)
{
if(((*front == 0) && (*rear == SIZE-1)) || ((*rear) + 1 == *front))
printf("\nElement not inserted. Queue is Full\n");
else {
if(*rear == SIZE-1)
*rear = 0;
else
(*rear)++;
queue[*rear] = item;
printf("\nPush Success\n");
}
if(*front == -1)
*front = 0;
}
void dequeue(int *front, int *rear, int *queue, int SIZE)
{
if(*front == -1)
printf("\nQueue is empty\n");
else {
printf("\nDeleted element is %d\n", queue[*front]);
if(*front == *rear)
*front = *rear = -1;
else {
if(*front == SIZE-1)
*front = 0;
else
(*front)++;
}
}
}
void display(int front, int rear, int *queue, int SIZE)
{
int i;
if(front == -1)
printf("\nQueue is empty\n");
else {
printf("\nQueue elements are\n");
if(rear < front) {
for(i = front; i <= SIZE-1; i++)
printf("%d\t", queue[i]);
for(i = 0; i <= rear; i++)
printf("%d\t", queue[i]);
} else {
for(i = front; i <= rear; i++)
printf("%d\t", queue[i]);
printf("\n");
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment