Binary Search Trees

For example, imagining that the window was above the dimensions 200x300 (width x height)
and was divided into 6 zones (see A, B, C, D, E and F), And i use the tree to
quickly and efficiently determine if a click in a window would be associated with
any node in the graph. If i click on the 150x150 position (the middle of the zone D). To
the standardization divide all the measurements from the horizontal size ( 'H') or
vertical ( 'V') of the window. Thus, the click would be normalized to the values (x, y) = (150/200,
150/300) = (0.75, 0.50).
I have all the data structures of the trees implemented i only need a head start on this since i dont know what the right way to go on this.

thanks in advange.
BST.png
VasconcelosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
You say that you have your data structures implemented, can you provide details on how you have implemented them?
0
jurobotCommented:
hi,
unfortunatelly, your question is not clear too much. But if you don't know essential operations to use binray search tree you can check some theory at http://en.wikipedia.org/wiki/Binary_search_tree
Algorithms can be rewrite to Java.

JS
0
VasconcelosAuthor Commented:
package javaappbtree;
// import java.util.Comparator;

/**
 * @author José Braga de Vasconcelos
 */
public class LinkedBinaryTree implements BinaryTree {
    // instance data member
    BinaryTreeNode root;
    // class data members
 
    public boolean isEmpty() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    // inserção ordenada
    public BinaryTreeNode insertBST(BinaryTreeNode node) {

        node.leftChild = null;
        node.rightChild = null;

        Comparable st1 = (Comparable) node.element;
       
        // if (bt == null) return node;
       
        BinaryTreeNode p = new BinaryTreeNode();
        p = this.root;
       
        while (true)
            if (st1.compareTo(p.element) < 0) {
                if (p.leftChild == null) {
                    p.leftChild = node;
                    return root;
                }
                else p = p.leftChild;
            }
            else if (p.rightChild == null) {
                     p.rightChild = node;
                     return root;
                 }
                 else p = p.rightChild;
        }

    // Attach node to the left of a specific node
    public void attachLeft(BinaryTreeNode node, BinaryTreeNode left) {
        node.leftChild = left;
    }
   
    // Attach node to the right of a specific node
    public void attachRight(BinaryTreeNode node, BinaryTreeNode right) {
        node.rightChild = right;
    }

    public BinaryTree removeLeft() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public BinaryTree removeRight() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}



// class Binary Tree Node
package javaappbtree;
// visible data members
public class BinaryTreeNode
{
    Object element;
    BinaryTreeNode leftChild;
    BinaryTreeNode rightChild;

    //constructors
    public BinaryTreeNode() {}

    public BinaryTreeNode(Object theElement)
        {element = theElement;}
   
    public BinaryTreeNode(Object theElement,
            BinaryTreeNode theleftChild,
            BinaryTreeNode therightChild)
    {
        element = theElement;
        leftChild = theleftChild;
        rightChild = therightChild;
    }

    // node visit method
    public static void visit(BinaryTreeNode t)
        {System.out.print(t.element + " ");}
   
    // preorder traversal
     public static void preOrder(BinaryTreeNode t)
     {
         if (t != null)
         {
            visit(t); //visit current node
            preOrder(t.leftChild); // left subtree
            preOrder(t.rightChild); // right subtree
         }      
     }

     // preorder traversal
     public static void inOrder(BinaryTreeNode t)
     {
         if (t != null)
         {
            inOrder(t.leftChild); // left subtree
            visit(t); //visit current node
            inOrder(t.rightChild); // right subtree
         }
     }

     public static void posOrder(BinaryTreeNode t)
     {
         if (t != null)
         {
            posOrder(t.leftChild); // left subtree
            posOrder(t.rightChild); // right subtree
            visit(t); //visit current node
         }
     }
}


package javaappbtree;
/**
 * @author José Braga de Vasconcelos
 */
public interface BinaryTree {
    public boolean isEmpty();
    public BinaryTreeNode insertBST(BinaryTreeNode node);
    public void attachLeft(BinaryTreeNode node, BinaryTreeNode left);
    public void attachRight(BinaryTreeNode node, BinaryTreeNode right);
    public BinaryTree removeLeft();
    public BinaryTree removeRight();
}


this is what i have so far
0
J KCommented:

See this for binary search implementation,
http://www.faqs.org/docs/javap/c11/s4.html 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.