Computer Science, asked by Aanchaldhingra868, 10 months ago

Queue delete and queue insert implementation using array

Answers

Answered by sushiladevi4418
1

Answer:

Queue delete and a queue insert implementation using array in C

Explanation:

#include <stdio.h>

#define MAX 20

#include<stdlib.h>

int queue_array[MAX];

int rear = - 1;

int front = - 1;

void insert()

{

     int add_item;

     if (rear == MAX - 1)

           printf("Queue Overflow \n");

     else

     {

           if (front == - 1)

                 /*If queue is initially empty */

                 front = 0;

           printf("\nEnter element : ");

           scanf("%d", &add_item);

           printf("\n%d is inserted in queue\n",add_item);

           printf("------------------------------\n");

           rear = rear + 1;

           queue_array[rear] = add_item;

     }

}  

void delete()

{

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

     {

           printf("Queue Underflow \n");

           return ;

     }

     else

     {

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

           printf("------------------------------\n");

           front = front + 1;

     }

}  

int main()

{

     printf("Perform operations on queue\n");

     printf("------------------------------\n");

     printf("\tMenu");

     printf("\n------------------------------\n");

     printf("1. Insert element \n");

     printf("2. Delete element \n");  

     printf("3. Exit\n");

     printf("------------------------------\n");

     int ch;

     while (1)

     {

           printf("Choose operation : ");

           scanf("%d", &ch);

           switch(ch)

           {

                 case 1:

                       insert();

                       break;

                 case 2:

                       delete();

                       break;

           

                 case 3:

                       exit(1);

                 default:

                       printf("Invalid operation \n");

           }

     }

     return 0;

}

Similar questions