C++ program queue
#include <iostream>
using namespace std;
int queue[100], n = 100, front = - 1, rear = - 1;
void Insert() {
int val;
if (rear == n - 1)
cout<<"Queue Overflow";
else {
if (front == - 1)
front = 0;
cout<<"Insert the element in queue : ";
cin>>val;
rear++;
queue[rear] = val;
}
}
void Delete() {
if (front == - 1 || front == rear) {
cout<<"Queue Underflow ";
return ;
} else {
cout<<"Element deleted from queue is : "<< queue[front];
front++;;
}
}
void Display() {
if (front == - 1)
cout<<"Queue is empty";
else {
cout<<"Queue elements are : ";
for (int i = front; i <= rear; i++)
cout<<queue[i]<<" ";
}
}
int main() {
int ch;
cout<<"1. Insert element to queue\n";
cout<<"2. Delete element from queue\n";
cout<<"3. Display all the elements of queue\n";
cout<<"4. Exit\n";
do {
cout<<"Enter your choice : ";
cin>>ch;
switch (ch) {
case 1: Insert();
break;
case 2: Delete();
break;
case 3: Display();
break;
case 4: cout<<"Exit";
break;
default: cout<<"Invalid choice";
}
} while(ch!=4);
return 0;
}
Comments
Post a Comment