find maximum element in stack
myStack = []
#Add some elements to stack
myStack = [1, 5, 2, 8, 0]
maximumValue = max(myStack)
print("The maximum value is", maximumValue)
find maximum element in stack
myStack = []
#Add some elements to stack
myStack = [1, 5, 2, 8, 0]
maximumValue = max(myStack)
print("The maximum value is", maximumValue)
java stack with max size
import java.util.Stack;
public class SizedStack<T> extends Stack<T> {
private int maxSize;
public SizedStack(int size) {
super();
this.maxSize = size;
}
@Override
public T push(T object) {
//If the stack is too big, remove elements until it's the right size.
while (this.size() >= maxSize) {
this.remove(0);
}
return super.push(object);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us