So akzeptabel, oder hat jemand ein Vorschlag für Verbesserung ?
Code: Alles auswählen
public T secMax(TreeNode<T> root, Comparator<T> cmp){
if(root==null){
return null;}
Stack<TreeNode<T>> stack = new Stack<TreeNode<T>>();
stack.push(root);
T secMax = null;
T max = root.key;
while(!stack.isEmpty()){
T aktelem = stack.pop();
if(aktelem.right!=null){
secMax = aktelem.key;
max = aktelem.right.key;
stack.push(aktelem.right);
}
if(aktelem.right == null && aktelem.left!=null){
secMax = aktelem.left.key;
stack.push(aktelem.left); }
}
return secMax;
}