二叉木(二)

2468 ワード

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;
    }

}