Improve the level of Java from here 2 - Data Structure (Binary Tree) [Transfer]

xiaoxiao2021-03-06  114

Raise the Java level starting from here 2 - Data Structure (Binary Tree) [Transfer] Java Pig Java (2003-04-22 17:09:24) -------------- -------------------------------------------------- ---------------- Last use of a small program explained the list, here is used to explain the binary tree in Java, the program is as follows: // ****** *********************************************************** **************** / / FileName: binarytreetest.java // purpose: test a binarytree with java // Date: Flyfan // Ver : 0.1 // *************************************************************** ********************************** Public class binarytreetest {public static void main (string args []) {binarytreetest b = new binarytreetest (); INT DATA [] = {12, 11, 34, 45, 67, 89, 56, 43, 22, 98}; binarytree root = new binarytree (data [0]); system.out.print ("The binary tree Data: "); for (int i = 1; i = root.data) {return searchkey (root.rightpoiter, key);} return searchkey (root.leftpoiter, key);}} class BinaryTree {int data; BinaryTree leftpoiter; BinaryTree rightpoiter; BinaryTree (int data) {this.data = data; leftpoiter = null; Rightpoiter = null;} public void inserttree (binarytree root, int data) {if (data> = root.data) {if (root.rightpoiter == null) {root.rightpoiter = New BinaryTree (DATA);

转载请注明原文地址:https://www.9cbs.com/read-97216.html

New Post(0)