As well as the private argument, this means that I can only use something like
MyBinaryTree bt = new MyBinaryTree(); int treeSize = bt.size();
Typically, the code may have comments to know what they are intended for. Sometimes clean code does not even need comments.
public int size() { return(size(root)); } private int size(Node node) { if (node == null) return(0); else { return(size(node.left) + 1 + size(node.right)); } }
In theory, all branches with children in a binary tree can also be treated as binary trees.

Note that size() will call the second one with the Node root as an argument, in this case it means that the count starts with A, inside it will be.
Size of the tree is count of items from A Items from A are 1 + Items from B + Items from C Items from B are 1 Items from C are 1 + Items from D + items from E
Now, why did you use a method with the same name and different arguments ?
There may be several reasons for doing this or not doing it. This usually means that there are several ways to do something or that you want to use something else by default, in which case size () will be used as the default root.
porfiriopartida
source share