หากคุณกำลังเขียนโค้ดไวท์บอร์ดการสัมภาษณ์หรือเพียงแค่วางแผนที่จะใช้ต้นไม้ความฟุ่มเฟื่อยของสิ่งเหล่านี้มีน้อยมาก
มันควรจะกล่าวต่อไปว่าเหตุผลที่ต้นไม้ไม่อยู่ในนั้นเช่นพูด a Pair(ซึ่งอาจพูดได้เหมือนกัน) เป็นเพราะคุณควรจะห่อหุ้มข้อมูลของคุณในชั้นเรียนที่ใช้มันและการใช้งานที่ง่ายที่สุดดูเหมือน:
/***
/* Within the class that's using a binary tree for any reason. You could 
/* generalize with generics IFF the parent class needs different value types.
 */
private class Node {
  public String value;
  public Node[] nodes; // Or an Iterable<Node> nodes;
}
ที่จริงมันเป็นต้นไม้ที่มีความกว้างตามอำเภอใจ
ถ้าคุณต้องการต้นไม้ไบนารีมันมักจะใช้กับเขตข้อมูลชื่อ:
private class Node { // Using package visibility is an option
  String value;
  Node left;
  Node right;
}
หรือถ้าคุณต้องการคู่ชีวิต:
private class Node {
  String value;
  Map<char, Node> nodes;
}
ตอนนี้คุณพูดว่าคุณต้องการ
  เพื่อให้สามารถรับชายด์ทั้งหมด (เรียงลำดับรายการหรือบางส่วนของสตริง) ที่กำหนดสตริงอินพุตที่แสดงโหนดที่กำหนด
ฟังดูเหมือนการบ้านของคุณ 
แต่เนื่องจากฉันแน่ใจว่ามีกำหนดส่งผ่าน ...
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
public class kidsOfMatchTheseDays {
 static private class Node {
   String value;
   Node[] nodes;
 }
 // Pre-order; you didn't specify.
 static public List<String> list(Node node, String find) {
   return list(node, find, new ArrayList<String>(), false);
 }
 static private ArrayList<String> list(
     Node node,
     String find,
     ArrayList<String> list,
     boolean add) {
   if (node == null) {
     return list;
   }
   if (node.value.equals(find)) {
     add = true;
   }
   if (add) {
     list.add(node.value);
   }
   if (node.nodes != null) {
     for (Node child: node.nodes) {
       list(child, find, list, add);
     }
   }
   return list;
 }
 public static final void main(String... args) {
   // Usually never have to do setup like this, so excuse the style
   // And it could be cleaner by adding a constructor like:
   //     Node(String val, Node... children) {
   //         value = val;
   //         nodes = children;
   //     }
   Node tree = new Node();
   tree.value = "root";
   Node[] n = {new Node(), new Node()};
   tree.nodes = n;
   tree.nodes[0].value = "leftish";
   tree.nodes[1].value = "rightish-leafy";
   Node[] nn = {new Node()};
   tree.nodes[0].nodes = nn;
   tree.nodes[0].nodes[0].value = "off-leftish-leaf";
   // Enough setup
   System.out.println(Arrays.toString(list(tree, args[0]).toArray()));
 }
}
สิ่งนี้ทำให้คุณได้ใช้เช่น:
$ java kidsOfMatchTheseDays leftish
[leftish, off-leftish-leaf]
$ java kidsOfMatchTheseDays root
[root, leftish, off-leftish-leaf, rightish-leafy]
$ java kidsOfMatchTheseDays rightish-leafy
[rightish-leafy]
$ java kidsOfMatchTheseDays a
[]