Question: where is the mistake in this code ? /* Write a method is Sorted that accepts a stack of integers as a parameter and returns

 where is the mistake in this code ? /* Write a

where is the mistake in this code ?

/* Write a method is Sorted that accepts a stack of integers as a parameter and returns true if the elements in the stack occur in ascending * (non-decreasing) order from top to bottom, and false otherwise. That is, * the smallest element should be on top, growing larger toward the bottom. An empty or one-element stack is considered to be sorted. When your method returns, the stack should be in the same state as when it was passed in. In * other words, if your method modifies the stack, you must restore it before returning. You may use one queue or stack (but not both) as auxiliary storage. Your solution should run in O(N) time, where N is the number of * elements of the stack. public boolean isSorted(Stack s1) { if(s1.size() s2 new Stack(); boolean sorted true; int ontop s1.pop(); s2.push(ontop); = while(!s1.isEmpty()) { int n = 51.pop(); if(n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!