#include <stdio.h>
#define MAX 6
int Q[MAX];
int front, rear;
void insertQ()
{
int data;
if(rear==MAX) {
printf("\nLinear Queue is Full: we cannot add an element.");
}
else{
printf("Enter Data: ");
scanf("\n%d", & data );
Q[rear] = data;
rear++;
}
}
void deleteQ()
{
if(rear==front){
printf("Queue is Empty. we cannot delete an element.");
}
else {
printf("\nDeleted Element is %d ", Q[front]);
front++;
}
}
void displayQ()
{
int i;
if(front==rear) {
printf("\nQueue is Empty. we dont Have any element yet!");
}
else {
printf("\nElements in the Queue is : ");
for(int i = front; i<rear; i++){
printf("%d ", Q[i]);
}
}
}
int menu()
{
int choice;
//clrscr();
printf("\nQueus Operation using Array: ");
printf("\n 1. insert Element.");
printf("\n 2. Delete Element.");
printf("\n 3. Display Elements.");
printf("\n 4. Quit.");
printf("\n\nEnter Your Choice: ");
scanf("%d", & choice);
return choice;
}
int main() {
int choice;
do
{
choice = menu();
switch(choice)
{
case 1: insertQ(); break;
case 2: deleteQ(); break;
case 3: displayQ(); break;
}
//getchoice();
}
while(1);
//return 0;
}
//OUTPUT:
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 50
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 60
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 70
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 50 60 70
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 80
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 50 60 70 80
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 2
Deleted Element is 50
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 60 70 80
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 20
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Enter Data: 30
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Linear Queue is Full: we cannot add an element.
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 60 70 80 20 30
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Linear Queue is Full: we cannot add an element.
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 60 70 80 20 30
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 2
Deleted Element is 60
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 3
Elements in the Queue is : 70 80 20 30
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice: 1
Linear Queue is Full: we cannot add an element.
Queus Operation using Array:
1. insert Element.
2. Delete Element.
3. Display Elements.
4. Quit.
Enter Your Choice:
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter