STL_QUEUE_MANAGEMENT
Submit solution
C++
Points:
10 (partial)
Time limit:
8.0s
Memory limit:
64M
Authors:
Problem type
Allowed languages
Queue and List Operations
Objective:
Write a C++ program to manage a queue and a list through a menu-driven interface. The program should allow users to perform various operations on both the queue and the list as specified in the given menu options. Task Description:
Your program should implement the following functionalities:
Queue Operations:
Enter a specified number of elements into the queue.
Dequeue (remove) the front element of the queue.
Check if the queue is empty. If not, print the elements of the queue.
List Operations:
Enter a specified number of elements into the list.
Remove the last element from the list.
Print the elements of the list using an iterator.
SAMPLE INPUT 1
1
6
12
23
34
45
56
67
5
7
SAMPLE OUTPUT 1
Menu:
1. Enter elements into the queue.
2. Enter elements into the list.
3. Dequeue the front element of the queue.
4. Remove the last element from the list.
5. Check if queue is empty and print the elements.
6. Print the elements of the list.
7. Exit.
choice is 1
choice is 5
Queue elements: 12 23 34 45 56 67
choice is 7
Exiting program.
SAMPLE INPUT 2
2
6
12
23
34
45
56
67
6
7
SAMPLE OUTPUT 2
Menu:
1. Enter elements into the queue.
2. Enter elements into the list.
3. Dequeue the front element of the queue.
4. Remove the last element from the list.
5. Check if queue is empty and print the elements.
6. Print the elements of the list.
7. Exit.
choice is 2
choice is 6
List elements: 12 23 34 45 56 67
choice is 7
Exiting program.
SAMPLE INPUT 3
2
6
12
23
34
45
56
67
6
4
6
7
SAMPLE OUTPUT 3
Menu:
1. Enter elements into the queue.
2. Enter elements into the list.
3. Dequeue the front element of the queue.
4. Remove the last element from the list.
5. Check if queue is empty and print the elements.
6. Print the elements of the list.
7. Exit.
choice is 2
choice is 6
List elements: 12 23 34 45 56 67
choice is 4
Last element removed from the list.
choice is 6
List elements: 12 23 34 45 56
choice is 7
Exiting program.
SAMPLE INPUT 4
1
6
12
23
34
45
56
67
5
3
5
7
SAMPLE OUTPUT 4
Menu:
1. Enter elements into the queue.
2. Enter elements into the list.
3. Dequeue the front element of the queue.
4. Remove the last element from the list.
5. Check if queue is empty and print the elements.
6. Print the elements of the list.
7. Exit.
choice is 1
choice is 5
Queue elements: 12 23 34 45 56 67
choice is 3
Dequeued element: 12
choice is 5
Queue elements: 23 34 45 56 67
choice is 7
Exiting program.
CODE TEMPLATE
#include <iostream>
#include <queue>
#include <list>
#include <sstream>
#include<iterator>
using namespace std;
void enterElementsToQueue(queue<int>& q) {
//@start-editable@
//@end-editable@
}
void enterElementsToList(list<int>& lst) {
//@start-editable@
//@end-editable@
}
void printQueue(queue<int> q) {
//@start-editable@
//@end-editable@
}
void printList(list<int> lst) {
list <int> :: iterator it;
cout << "\nList elements: ";
//@start-editable@
//@end-editable@
}
int main() {
queue<int> myQueue;
list<int> myList;
int choice;
cout << "Menu:\n";
cout << "1. Enter elements into the queue.\n";
cout << "2. Enter elements into the list.\n";
cout << "3. Dequeue the front element of the queue.\n";
cout << "4. Remove the last element from the list.\n";
cout << "5. Check if queue is empty and print the elements.\n";
cout << "6. Print the elements of the list.\n";
cout << "7. Exit.\n";
while (true) {
cin >> choice;
cout<<"\nchoice is "<<choice;
switch (choice) {
case 1:
enterElementsToQueue(myQueue);
break;
case 2:
enterElementsToList(myList);
break;
case 3:
//@start-editable@
//@end-editable@
break;
case 4:
//@start-editable@
//@end-editable@
break;
case 5:
//@start-editable@
//@end-editable@
break;
case 6:
//@start-editable@
//@end-editable@
break;
case 7:
cout << "\nExiting program.";
return 0;
default:
cout << "\nInvalid choice, please try again.";
}
}
return 0;
}
Comments