问题
Is there a java library that has Binary Tree that I can use? I am not looking forward to test and implement my own.
回答1:
The Java standard API only contains libraries that are universally useful and non-trivial to implement. A basic tree is trivial to implement:
class BinaryTree {
BinaryTree left;
BinaryTree right;
Object value;
}
Non-trivial trees are not universally useful: either they are needed as a part of the application data model, which is better modeled using domain specific classes (component has-a list of sub-components), or they are used as a part of a specific algorithm. Algorithms usually require a specific structure from the nodes (e.g. the color or weight of the node needed to maintain the tree balanced), so a generic tree node makes little sense.
回答2:
What about http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html
A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
回答3:
do you mean something like this: http://www.codeproject.com/Articles/53366/Binary-Trees-in-Java
http://www.java2s.com/Code/Java/Collections-Data-Structure/BinaryTree.htm
回答4:
Maybe Swing's TreeModel and its implementation - DefaultTreeModel.
回答5:
There is a sample implementation on this page here: -around at the bottom half of the page or so-
http://cslibrary.stanford.edu/110/BinaryTrees.html
来源:https://stackoverflow.com/questions/9900454/looking-for-a-java-library-that-has-implemented-binary-tree