Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

DS || Section B || Pgm 7 || Program to implement simple queue.

 #include <stdio.h>

#include<stdlib.h>


#define MAX 50


void Qinsert();

void Qdelete();

void Qdisplay();

int queue[MAX];

int rear = - 1;

int front = - 1;

void main()

{

int choice;

printf("1.Insert\n");

printf("2.Delete\n");

printf("3.Display\n");

printf("4.Quit \n");

while (1)

{


printf("Enter your choice : ");

scanf("%d", &choice);

switch (choice)

{

case 1:

Qinsert();

break;

case 2:

Qdelete();

break;

case 3:

Qdisplay();

break;

case 4:

exit(1);

default:

printf("Wrong choice \n");

}

}

}


void Qinsert()

{

int add_item;

if (rear == MAX - 1)

printf("Queue Overflow \n");

else

{

if (front == - 1)

/*If queue is initially empty */

front = 0;

printf("Inset the element in queue : ");

scanf("%d", &add_item);

queue[++rear] = add_item;

}

}


void Qdelete()

{

if (front == - 1 || front > rear)

{

printf("Queue Underflow \n");

return ;

}

else

printf("Element deleted from queue is : %d\n", queue[front++]);


}


void Qdisplay()

{

int i;

if (front == - 1)

printf("Queue is empty \n");

else

{

printf("Queue is : \n");

for (i = front; i <= rear; i++)

printf("%d ", queue[i]);

printf("\n");

}

}

Post a Comment

0 Comments