二叉树(二)

package cn.jbit.nodetree.test;

import java.util.Arrays;

public class Test {

    //二叉树测试主方法
    public static void main(String[] args) {
        int[] values = new int[8];

        for (int i = 0; i < values.length; i++) {
            int num = (int)(Math.random()*20);
            boolean flag = constain(values,num);
            if(flag){
                i--;
            }else{
                values[i] = num;
            }
        }
        Node root = new Node(values[0]);
        for (int i = 1; i < values.length; i++) {
            root.add(values[i]);
        }

        System.out.println(Arrays.toString(values));
        boolean f = root.find(15);
        System.out.println(f);
    }

    public static boolean constain(int[] values, int num){
        for (int j = 0; j < values.length; j++) {
            if(values[j] == num){
                return true;
            }
        }
        return false;
    }

}

你可能感兴趣的:(二叉树)