import java.util.*;
import java.lang.*;
import java.io.*;
class Node {
public List<Node> children;
this.value = value;
this.children = new ArrayList<Node>();
}
public void addChild(Node node) {
children.add(node);
}
public static Node createSample() {
Node node = new Node(10.0);
Node node1 = new Node(15.0);
Node node2 = new Node(6.0);
Node node3 = new Node(11.0);
Node node4 = new Node(14.0);
Node node5 = new Node(5.0);
node.addChild(node1);
node.addChild(node2);
node.addChild(node3);
node.addChild(node4);
Node node51 = new Node(8.0);
Node node52 = new Node(7.0);
node5.addChild(node51);
node5.addChild(node52);
node.addChild(node5);
Node node11 = new Node(9.0);
Node node12 = new Node(5.5);
node1.addChild(node11);
node1.addChild(node12);
Node node21 = new Node(5.7);
Node node22 = new Node(12.0);
node2.addChild(node21);
node2.addChild(node22);
Node node31 = new Node(13.0);
Node node32 = new Node(1.0);
node22.addChild(node31);
node22.addChild(node32);
return node;
}
}
class StackNode {
public Node node;
public boolean largerChildrenPushed;
public StackNode(Node n) {
this.node = n;
this.largerChildrenPushed = false;
}
}
class Ideone
{
public static void process(Node node) {
st.push(new StackNode(node));
while(!st.empty()) {
StackNode stParent = (StackNode)st.pop();
Node parent = stParent.node;
if(!stParent.largerChildrenPushed) {
for (int i = parent.children.size() - 1; i >= 0; i--) {
Node child = parent.children.get(i);
if (child.value >= parent.value) {
st.push(new StackNode(child));
}
}
st.push(stParent);
stParent.largerChildrenPushed = true;
for (int i = parent.children.size() - 1; i >= 0; i--) {
Node child = parent.children.get(i);
if (child.value < parent.value) {
st.push(new StackNode(child));
}
}
}
else {
System.
out.
println(parent.
value); }
}
}
{
process(Node.createSample());
}
}