



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




/* Class containing left and right child of current node and key value*/ class Node { int data; Node left, right; public Node(int item) { data = item; left = right = null; } } static int sumOfLeaves(Node root) { if(root != null) { if(root.left != null || root.right != null) { return sumOfLeaves(root.left)
// Example of Stack Push() and Pop() public class StackDemo { public static void main(String args[]) { // creating stack Stack st = new Stack(); // populating stack st.push("Java"); st.push("Source"); st.push("code"); // removing top object System.out.println("Removed object is: "+st.pop()); // elements after remove System.out.println("Elements after remove: "+st); } }
/* importing the necessary class / import java.util.Stack; / Class containing left and right child of current node and key value*/ class Node { int data; Node left, right; public Node(int item) { data = item; left = right = null; } } class BinaryTree { Node root;
// non-recursive method for inorder traversal void inorder() { if (root == null) { return; } // use stack to keep track of the Nodes you still need to visit. // Keep in mind that the Stack starts empty Stack
if (tree.isIsomorphic(tree.root1, tree.root2) == true) System.out.println("Yes"); else System.out.println("No"); } }
computingDepths(v, d) { v.depth=d; if ( v has no child ) return; else for each child v′ do computingDepths(v′, d+1); return; }