ARRAY IMPLEMENTATION QUEUE.

 If Screen is half, please rotate the Mobile then it is full program available

ARRAY IMPLEMENTATION QUEUE.

6. Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue

with maximum size MAX)

a. Insert an Element on to Circular QUEUE

b. Delete an Element from Circular QUEUE

c. Demonstrate Overflow and Underflow situations on Circular QUEUE

d. Display the status of Circular QUEUE

e. Exit

Support the program with appropriate functions for each of the above operations


#include <stdio.h>

#include <stdlib.h>


int queue[100];

int queueSize;

int front = 0, rear = 0;


void queueFull ( void )

{

printf ( "\n\n Insertion Failed: Queue is Full\n\n" );

if ( front ) rear = front - 1;

else rear = queueSize - 1;

}


int queueEmpty ( void )

{

printf ( "\n\nQueue is Empty\n\n" );

front = rear = 0;

}


void addq ( int item )

{

rear = ( rear + 1 ) % queueSize;

if ( front == rear )

{

queueFull ( );

return;

}

queue[rear] = item;

printf ( "\n\n Item is inserted Successfully\n\n" );

}


void deleteq ( void )

{

int item;

if ( front == rear )

{

queueEmpty ( );

return;

}

front = ( front + 1 ) % queueSize;

printf ( "\n\n Deleted Item: %d\n\n", queue[front] );

}


void displayQueue ( void )

{

int i;

if ( front == rear )

{

queueEmpty ( );

return;

}

printf ( "\n\n Circular Queue Elements are..\n\n" );

i = ( front + 1 ) % queueSize;

while ( i != rear )

{

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

i = ( i + 1 ) % queueSize;

}

printf ( "\t%d\n\n", queue[rear] );

printf ( "\n\n" );

}


int main ( void )

{

int item;

int ch;


printf ( "\n\nEnter the size of Circular Queue Memory: ?\b" );

scanf ( "%d", &queueSize );

queueSize = queueSize + 1;

do{

system("cls");

printf ("\n\n\t\t CIRCULAR QUEUE DEMONSTRATION\n\n" );

printf ("\n\n\t\t 1. Insert\t\t2. Delete\n\n" );

printf ("\n\n\t\t 3. Display\t\t4. Exit\n\n" );

printf ( "\n\n Enter your choice: ?\b" );

scanf ( "%d", &ch );

switch ( ch )

{

case 1: printf ( "\n\nEnter an Element to insert: ?\b" );

scanf ( "%d", &item );

addq ( item );

break;

case 2: deleteq ( );

break;

case 3: displayQueue ( );

break;

case 4: return 0;

default: printf ( "\n\nInvalid Option\n\n" );

}

fflush(stdin);

getchar();

}while ( 1 );

}


/*


OUTPUT:-


Enter the size of Circular Queue Memory: 5


                CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete


                3. Display              4. Exit


Enter your choice: 2


Queue is Empty


                CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete


                3. Display              4. Exit


Enter your choice: 3


Queue is Empty


                CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete


                3. Display              4. Exit


Enter your choice: 1


Enter an Element to insert: 10

Item is inserted Successfully


Enter your choice: 1


Enter an Element to insert: 20

Item is inserted Successfully


Enter your choice: 1


Enter an Element to insert: 30

Item is inserted Successfully


Enter your choice: 1


Enter an Element to insert: 40

Item is inserted Successfully


Enter your choice: 1


Enter an Element to insert: 50

Item is inserted Successfully


Enter your choice: 1


Enter an Element to insert: 60

Insertion Failed: Queue is Full


                CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete


                3. Display              4. Exit


Enter your choice: 3


Circular Queue Elements are..


        10


        20


        30


        40


        50


                CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete

                3. Display              4. Exit


Enter your choice: 2

Deleted Item: 10


Enter your choice: 2

Deleted Item: 20


                CIRCULAR QUEUE DEMONSTRATION

                1. Insert               2. Delete


                3. Display              4. Exit


Enter your choice: 3


Circular Queue Elements are..


        30


        40


        50


CIRCULAR QUEUE DEMONSTRATION


                1. Insert               2. Delete

                3. Display              4. Exit


Enter your choice: 2

Deleted Item: 30


Enter your choice: 2

Deleted Item: 40


Enter your choice: 2

Deleted Item: 50


Enter your choice: 2

Queue is Empty


                CIRCULAR QUEUE DEMONSTRATION

                1. Insert               2. Delete


                3. Display              4. Exit

Enter your choice: 3

Queue is Empty





  1. Application of Stack: Evaluation of Suffix Expression

  2. Array Implementation Queue

Post a Comment

Previous Post Next Post

Contact Form