Question: Write a method called isConsecutive that accepts a stack of integers as a parameter and that returns true if the stack contains a sequence of

Write a method called isConsecutive that accepts a stack of integers as a parameter and that returns true if the stack contains a sequence of consecutive integers starting from the bottom of the stack.

Consecutive integers are integers that come one after the other, as in 3, 4, 5, etc. If the stack stores [5, 6, 7, 8, 9, 10] , your method should return true . If the stack had instead contained [7, 8, 9, 10, 12] , your method should return false because the numbers 10 and 12 are not consecutive. Notice that we look at the numbers starting at the bottom of the stack. Any stack with fewer than two values should be considered to be a list of consecutive integers. Your method must restore the parameter stack to its original state before returning. Use one queue as auxiliary storage.

Step by Step Solution

3.33 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public bo... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!