Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
6
Indexable
Never
#include <stdio.h>

#include <stdlib.h>

# define SIZE 100

void enqueue();

void dequeue();

void show();

void modify();

int inp_arr[SIZE];

int Rear = - 1;

int Front = - 1;

int main(){

int ch;

while (1){

printf("\n1.Enqueue Operation\n");

printf("2.Dequeue Operation\n");

printf("3.Display the Queue\n");

printf("4.Modify the Queue\n");

printf("5.Exit\n");

printf("Enter your choice of operations : ");

scanf("%d", &ch);

switch (ch){

case 1:

enqueue();

break;

case 2:

dequeue();

break;

case 3:

show();

break;

case 4:

modify();

break;

case 5:

exit(0);

default:

printf("Incorrect choice \n");

}

}

}

void enqueue(){

int insert_item;

if (Rear == SIZE - 1)

printf("Overflow \n");

else{

if (Front == - 1)

Front = 0;

printf("Element to be inserted in the Queue\n : ");

scanf("%d", &insert_item);

Rear = Rear + 1;

inp_arr[Rear] = insert_item;

}

}

void dequeue(){

if (Front == - 1 || Front > Rear){

printf("Underflow \n");

return ;

}

else{

printf("Element deleted from the Queue: %d\n", inp_arr[Front]);

Front = Front + 1;

}

}

void show(){

if (Front == - 1)

printf("Empty Queue \n");

else{

printf("Queue: \n");

for (int i = Front; i <= Rear; i++)

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

printf("\n");

}

}

void modify(){

int n = Rear - Front + 1;

if (Front == - 1)

printf("Empty Queue \n");

else{

if(n<=0) printf("Empty Queue \n");

int odd=0 , even=0 ;

int odd_arr[n] , even_arr[n] , x=0 , y=0;

for(int i=Front ; i<=Rear ; i++){

if(inp_arr[i]%2) {

odd++;

odd_arr[x++] = inp_arr[i];

}

else {

even++;

even_arr[y++] = inp_arr[i];

}

}

x=0 ;

for(int i=Front ; i<Front+odd ; i++){

inp_arr[i] = odd_arr[x++];

}

y=0 ;

for(int i=Front+odd ; i<=Rear ; i++){

inp_arr[i] = even_arr[y++];

}

printf("\n");

}

}