cis22c/02-queues/main.cpp
2024-04-28 11:54:46 -07:00

70 lines
2.0 KiB
C++

/*
Written by: Iurii Tatishchev
=================================
Project: Queue ADT
Parallel queues. Create two queues:
- the first queue contains the names of the students enrolled in CIS 22C
- the second queue contains the number of units each student is taking this quarter
*/
#include <iostream>
#include <string>
#include "QueueADT.h"
using namespace std;
int main() {
// Create the first queue (strings)
Queue<string> names;
// Loop to enter an unknown number of names, one per line.
// The loop stops when you enter #.
// As you are entering names, they are to be inserted into the first queue.
string item;
getline(cin, item);
while (item != "#") {
names.push(item);
getline(cin, item);
}
if (names.isEmpty()) {
cout << "Empty Queues!\n";
return 0;
}
// Test the getLength function: - display the number of elements in the first queue
cout << names.getLength();
// Create the second queue (doubles)
Queue<double> numbers;
// Test the getLength function: - display the number of elements in the second queue
// (it should be 0!)
cout << " " << numbers.getLength() << "\n";
// Write another loop to enter the number of units (double) into a parallel queue.
for (int i = 0; i < names.getLength(); i++) {
double units;
cin >> units;
numbers.push(units);
}
// Display the two queues in parallel.
for (int i = names.getLength(); i > 0; i--) {
names.push(names.pop());
numbers.push(numbers.pop());
cout << names.peekRear() << " " << numbers.peekRear() << "\n";
}
// On the next line display the front and rear elements in the first queue.
cout << "Front of the queues: " << names.peek() << " " << numbers.peek() << "\n";
// On the last line display the front and the rear elements in the second queue.
cout << "Rear of the queues: " << names.peekRear() << " " << numbers.peekRear() << "\n";
return 0;
}