Entfernen Sie das minimale Element aus Stack Java
public static void removeMin(Stack stack) {
int min = stack.readTop();
int e;
Stack newStack1 = new Stack(7); //7 is the size of the stack
while (!stack.isEmpty()) {
e = stack.pop();
newStack1.push(e);
if (e < min) {
min = e;
}
}
System.out.println("\nMin element: " + min);
while (!newStack1.isEmpty()) {
e = newStack1.pop();
if (e != min) {
stack.push(e);
}
}
}
Jittery Jay