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

Question:

Write a method called isSorted that accepts a stack of integers as a parameter and returns true if the elements in the stack occur in ascending (nondecreasing) order from top to bottom. That is, the smallest element should be on top, growing larger toward the bottom. For example, if the stack stores [20, 20, 17, 11, 8, 8, 3, 2], your method should return true. An empty or one-element stack is considered to be sorted. Your method must restore the parameter stack to its original state before returning. Use one queue or stack (but not both) 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
Question Posted: