The root recursively traverses the binary tree and outputs a node with a weighted value greater than 50

Source: Internet
Author: User

/** * @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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.