20 likes | 187 Views
public class Client { public Object clientItemAt(Stack s, int n) { //PRE 1<=n<=myStack.count() Object returnValue; Stack tmpStack= new LinkedStack(); for(int i= s.count(); n<=i; i--) { tmpStack.put(s.item());
E N D
public class Client { public Object clientItemAt(Stack s, int n) { //PRE 1<=n<=myStack.count() Object returnValue; Stack tmpStack= new LinkedStack(); for(int i= s.count(); n<=i; i--) { tmpStack.put(s.item()); s.remove(); } returnValue= tmpStack.item(); while(!tmpStack.isEmpty()) { s.put(tmpStack.item()); tmpStack.remove(); } return returnValue; } } Fx: