logo CodeStepByStep logo

isConsecutive

Language/Type: C++ PriorityQueue collections
Related Links:

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.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.