Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. bool isEmptyQ (const Queue& q) {
  2. return nullptr == q.first;
  3. }
  4.  
  5. void printQueue (const Queue& q) {
  6. if (isEmptyQ(q))
  7. return;
  8.  
  9. Qnode *iterator = q.first;
  10.  
  11. while (iterator != nullptr) {
  12. cout << iterator->val << " ";
  13. iterator = iterator->next;
  14. }
  15. }
  16.  
  17. void printPQ (const PQ& pq) {
  18. if (isEmptyPQ(pq)) return;
  19.  
  20. PQ temp = pq;
  21.  
  22. cout << "numPr " << numPriorities(pq) << " size " << sizePQ(pq) << endl;
  23.  
  24. while (nullptr != temp) {
  25. cout << "p" << temp->priority << " s" << sizeByPriority(pq, temp->priority) << endl;
  26. printQueue(temp->q);
  27. cout << endl;
  28. temp = temp->next;
  29. }
  30. }
  31.  
  32. int main (int argc, char* argv[]) {
  33. PQ pq1;
  34. initPQ (pq1);
  35. cout << "======\nTest 1" << endl;
  36. cout << "Expected: <nothing>" << endl;
  37. cout << "Output:" << endl;
  38. printPQ(pq1);
  39. cout << "======" << endl << endl;
  40.  
  41. enterPQ(pq1, "a", 3);
  42. cout << "======\nTest 2" << endl;
  43. cout << "Expected: 1 1 ## 3 1 a" << endl;
  44. cout << "Output:" << endl;
  45. printPQ(pq1);
  46. cout << "======" << endl << endl;
  47.  
  48. enterPQ(pq1, "b", 1);
  49. cout << "======\nTest 3" << endl;
  50. cout << "Expected: 2 2 ## 1 1 b ## 3 1 a" << endl;
  51. cout << "Output:" << endl;
  52. printPQ(pq1);
  53. cout << "======" << endl << endl;
  54.  
  55. enterPQ(pq1, "c", 3);
  56. enterPQ(pq1, "d", 4);
  57. enterPQ(pq1, "e", 3);
  58. cout << "======\nTest 4" << endl;
  59. cout << "Expected: 3 5 ## 1 1 b ## 3 3 a c e ## 4 1 d" << endl;
  60. cout << "Output:" << endl;
  61. printPQ(pq1);
  62. cout << "======" << endl << endl;
  63.  
  64. leavePQ(pq1);
  65. cout << "======\nTest 5" << endl;
  66. cout << "Expected: 2 4 ## 3 3 a c e ## 4 1 d" << endl;
  67. cout << "Output:" << endl;
  68. printPQ(pq1);
  69. cout << "======" << endl << endl;
  70.  
  71. leavePQ(pq1);
  72. // leavePQ(pq1);
  73. cout << "======\nTest 6" << endl;
  74. cout << "Expected: 2 3 ## 3 2 c e ## 4 1 d" << endl;
  75. cout << "Output:" << endl;
  76. printPQ(pq1);
  77. cout << "======" << endl << endl;
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement