0% found this document useful (0 votes)
6 views

Assignment 9

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 9

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>

#include<stdlib.h>

#define MAX 5

struct queue

int front,rear;

int a[MAX];

}q1;

void enqueue();

void dequeue();

void display();

int main()

int ch;

q1.front = -1;

q1.rear = -1;

do{

printf("\n1.Enqueue\n2.Dequeue\n");

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

scanf("%d",&ch);

switch(ch)

case 1:

enqueue();

display();

break;

case 2:
dequeue();

display();

break;

default:

printf("Invalid");

}while(ch<3);

void enqueue()

int n;

printf("\nEnter the element you want to add\n");

scanf("%d",&n);

if(q1.rear == MAX-1)

printf("The queue is full\n");

else if(q1.front == -1 && q1.rear == -1)

q1.rear ++;

q1.front++;

q1.a[q1.rear] = n;

else

q1.rear++;

q1.a[q1.rear] = n;

}
}

void dequeue()

if(q1.front == -1 && q1.rear == -1)

printf("It is Empty!!\n");

else if(q1.front == q1.rear)

q1.rear = -1;

q1.front = -1;

else

int x = q1.a[q1.front];

printf("The element that is removed is %d\n",x);

q1.front++;

void display()

for(int i = q1.front; i <= q1.rear; i++)

printf("%d\t",q1.a[i]);

OUTPUT:

PS D:\S.Y\C programming> gcc queue_s.c


PS D:\S.Y\C programming> ./a.exe

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

2 3

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

2 3 5

1.Enqueue

2.Dequeue

Enter your choice:

1
Enter the element you want to add

2 3 5 7

1.Enqueue

2.Dequeue

Enter your choice:

The element that is removed is 2

3 5 7

1.Enqueue

2.Dequeue

Enter your choice:

Invalid

You might also like