/** * @author Cody */public class search{public static void Main (string[] args) {node A = new Node (); A.setvalue (51); Node B = new node (); B.setvalue (52); Node C = new node (); C.setvalue (53); Node D = new node (); D.setvalue (49); Node E = new node (); E.setvalue (73); A.setleftchild (B); B.setleftchild (D); A.setrightchild (C); C.setrightchild (E); Out (A); /** * Root recursively traverses the binary tree and outputs a node with a weight greater than 50 * @param root root node */private static void out (node root) {if (root.get Leftchild () = null) {out (Root.getleftchild ()); } if (Root.getvalue () >) {System.out.println (Root.getvalue ()); } if (root.getrightchild () = null) {out (Root.getrightchild ()); }}}/** * Custom node type */class node{private int value = 0; Private Node leftchild = null; Private Node rightchild = null; Public Node Getleftchild () {return this.leftchild; } public void Setleftchild (node node) {this.leftchild = node; } public Node Getrightchild () {return this.rightchild; } public void Setrightchild (node node) {this.rightchild = node; } public int GetValue () {return this.value; } public void SetValue (int value) {this.value = value; }}
The root recursively traverses the binary tree and outputs a node with a weighted value greater than 50