Write a method called isConsecutive that accepts a stack of integers as a parameter and that returns

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 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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Building Java Programs A Back To Basics Approach

ISBN: 9780135471944

5th Edition

Authors: Stuart Reges, Marty Stepp

Question Posted: