Created
February 26, 2019 16:49
-
-
Save iamirulofficial/f72321ea2d36f3ad8fa6b162959de3be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include<stdlib.h> | |
#define MAX 5 | |
void insert(); | |
void delete(); | |
void display(); | |
int q[MAX]; | |
int rear = - 1; | |
int front = - 1; | |
main() | |
{ | |
int choice; | |
printf(" 1.Insert element to queue \n 2.Delete element from queue \n 3. Display element from queue \n 4.Exit \n "); | |
while(1) | |
{ | |
printf("Enter your choice : "); | |
scanf("%d", &choice); | |
switch (choice) | |
{ | |
case 1: | |
insert(); | |
break; | |
case 2: | |
delete(); | |
break; | |
case 3: | |
display(); | |
break; | |
case 4: | |
exit(1); | |
default: | |
printf("Wrong choice \n"); | |
} | |
} | |
} | |
void insert() | |
{ | |
int elm; | |
if (rear == MAX - 1) | |
printf("Queue Overflow \n"); | |
else | |
{ | |
if (front == - 1) | |
front = 0; | |
printf("Inset the element in queue : "); | |
scanf("%d", &elm); | |
rear = rear + 1; | |
q[rear] = elm; | |
} | |
} | |
void delete() | |
{ | |
if (front == - 1 || front > rear) | |
{ | |
printf("Queue Underflow \n"); | |
return; | |
} | |
else | |
{ | |
printf("Element deleted from queue is : %d\n", q[front]); | |
front = front + 1; | |
} | |
} | |
void display() | |
{ | |
int i; | |
if (front == - 1) | |
printf("Queue is empty \n"); | |
else | |
{ | |
printf("Queue is : \n"); | |
for (i = front; i <= rear; i++) | |
printf("%d ", q[i]); | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment