logo CodeStepByStep logo

isConsecutive

Language/Type: C++ PriorityQueue collections
Related Links:
Author: Marty Stepp (on 2016/06/16)

Write a function named isConsecutive that accepts as a parameter a reference to a PriorityQueue of integers, and returns true if the queue contains a sequence of consecutive integers starting from the front of the queue. We are talking about the element values in the priority queue, not their priorities. Consecutive integers are integers that come one after the other, as in 5, 6, 7, 8, 9, etc., so if the queue stores {1:7, 4:8, 16:9, 29:10, 34:11}, your function should return true. (Keep in mind that a priority queue displays its elements as "priority:value", so in the preceding example, the only values that matter are the 7, 8, 9, etc., not the 1, 4, 16, etc.) Your function should also return true if passed an empty queue. If your function modifies the state of the queue during its computation, it should restore the queue before it returns. You may use one collection as auxiliary storage.

Type your C++ solution code here:


This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.


Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.