Generic tree implementation in Java

Here it comes: abstract class TreeNode implements Iterable<TreeNode> { private Set<TreeNode> children; public TreeNode() { children = new HashSet<TreeNode>(); } public boolean addChild(TreeNode n) { return children.add(n); } public boolean removeChild(TreeNode n) { return children.remove(n); } public Iterator<TreeNode> iterator() { return children.iterator(); } } I am well trusted, but haven’t tested the implementation.

How can you get the call tree with Python profilers?

I just stumbled on this as well, and spent some time learning how to generate a call graph (the normal results of cProfile is not terribly informative). Future reference, here’s another way to generate a beautiful call-tree graphic with cProfile + gprof2dot + graphViz. ——————— Install GraphViz: http://www.graphviz.org/Download_macos.php easy_install gprof2dot Run profile on the code. … Read more

In GitHub URL’s: what is the difference between a tree and a blob?

GitHub’s website currently seems to be: Using blob for files, and tree for directories, in URLs; Redirecting browsers which request file URLs containing tree to contain blob instead; and Redirecting browsers which request directory URLs containing blob to URLs containing tree instead. It’s possible that GitHub’s website, at the time you asked the question, was … Read more

Tree implementation in Java (root, parents and children)

import java.util.ArrayList; import java.util.List; public class Node<T> { private List<Node<T>> children = new ArrayList<Node<T>>(); private Node<T> parent = null; private T data = null; public Node(T data) { this.data = data; } public Node(T data, Node<T> parent) { this.data = data; this.parent = parent; } public List<Node<T>> getChildren() { return children; } public void setParent(Node<T> … Read more

Reverse A Binary Tree (Left to Right) [closed]

You can use recursion. We swap the left and right child of a node, in-place, and then do the same for its children: static void reverseTree(final TreeNode root) { final TreeNode temp = root.right; root.right = root.left; root.left = temp; if (root.left != null) { reverseTree(root.left); } if (root.right != null) { reverseTree(root.right); } } … Read more

CMD tree command limit number of levels

Since I didn’t found complete answer here. Here it is: Windows CMD doesn’t support -L depth levels. Install CygWin https://www.cygwin.com. In Cygwin make sure you pick Utilities / Tree package installed. Open CygWin and navigate to your folder, like cd ../../cygdrive/c/myFolder. List tree structure and save as result.txt tree -L 3 >result.txt.