Write an interactive menu driven c++ program to implement queue using array. 1.Insert an element in queue 2.Delete an element from queue. 3.Show the contents of the queue. 4.Exit
1
Expert's answer
2013-02-06T07:45:19-0500
#include <iostream>
using namespace std;
void main() { char choice; int tmp;
int queue[100]; int queueLength = 0;
cout << endl; cout << " 1. Insert an element in queue" << endl; cout << " 2. Delete an element from queue" << endl; cout << " 3. Show the contents of the queue" << endl; cout << " 4. Exit" << endl << endl;
while (true) { cout << "Choose the menu item: "; cin >> choice;
switch (choice) { case '1': cout << "Enter and integer value: "; cin >> tmp;
case '2': if (queueLength > 0) { queueLength--; cout << "The following element has been dequeued: " << queue[0] << endl << endl;
/* Shift array values left by one position * to dequeue the first element of the queue */ for (int c = 0; c < queueLength; c++) queue[c] = queue[c + 1]; } else cout << "The queue is empty." << endl << endl; break;
case '3': if (queueLength == 0) { cout << "The queue is empty." << endl << endl; break; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment