Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool isEmptyQ (const Queue& q) {
- return nullptr == q.first;
- }
- void printQueue (const Queue& q) {
- if (isEmptyQ(q))
- return;
- Qnode *iterator = q.first;
- while (iterator != nullptr) {
- cout << iterator->val << " ";
- iterator = iterator->next;
- }
- }
- void printPQ (const PQ& pq) {
- if (isEmptyPQ(pq)) return;
- PQ temp = pq;
- cout << "numPr " << numPriorities(pq) << " size " << sizePQ(pq) << endl;
- while (nullptr != temp) {
- cout << "p" << temp->priority << " s" << sizeByPriority(pq, temp->priority) << endl;
- printQueue(temp->q);
- cout << endl;
- temp = temp->next;
- }
- }
- int main (int argc, char* argv[]) {
- PQ pq1;
- initPQ (pq1);
- cout << "======\nTest 1" << endl;
- cout << "Expected: <nothing>" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- enterPQ(pq1, "a", 3);
- cout << "======\nTest 2" << endl;
- cout << "Expected: 1 1 ## 3 1 a" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- enterPQ(pq1, "b", 1);
- cout << "======\nTest 3" << endl;
- cout << "Expected: 2 2 ## 1 1 b ## 3 1 a" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- enterPQ(pq1, "c", 3);
- enterPQ(pq1, "d", 4);
- enterPQ(pq1, "e", 3);
- cout << "======\nTest 4" << endl;
- cout << "Expected: 3 5 ## 1 1 b ## 3 3 a c e ## 4 1 d" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- leavePQ(pq1);
- cout << "======\nTest 5" << endl;
- cout << "Expected: 2 4 ## 3 3 a c e ## 4 1 d" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- leavePQ(pq1);
- // leavePQ(pq1);
- cout << "======\nTest 6" << endl;
- cout << "Expected: 2 3 ## 3 2 c e ## 4 1 d" << endl;
- cout << "Output:" << endl;
- printPQ(pq1);
- cout << "======" << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement