Main method

mail@pastecode.io avatar
unknown
java
a year ago
1.3 kB
0
Indexable
Never
package LAB5;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        // Create a new BinarySearchTree object using the array of values
        BinarySearchTree myBST = new BinarySearchTree();
        myBST.insert(3);
        myBST.insert(8);
        myBST.insert(1);
        myBST.insert(4);
        myBST.insert(6);
        myBST.insert(2);
        myBST.insert(10);
        myBST.insert(9);
        myBST.insert(20);
        myBST.insert(25);
        myBST.insert(15);
        myBST.insert(16);
        System.out.print("The tree elements orgranized in increasing order : ");
        myBST.inOrderTraversal();
        System.out.println();
        System.out.println("Please enter the number you want to check is in the tree: ");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        scanner.close();
        if(myBST.contains(num) == true)
        {
            System.out.println("The tree contains: " + num);
        }
        if(myBST.contains(num) != true)
        {
            System.out.println("The tree does not contain: " + num);
        }
        myBST.delete(2);
        myBST.delete(4);
        myBST.delete(10);
        System.out.print("The tree elements orgranized in increasing order after the edits : ");
        myBST.inOrderTraversal();
}
}