SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 09 Nov 2017 My Price 10.00

laboratory, you will be using the class BinarySearchTree.

Thanks for the help. Please code by yourself. If you have any question, please let me know.

  • public class BinarySearchTree< E extends Comparable<E> > {

        // A static nested class used to store the elements of this tree

        private static class Node<E> {
            private E value;
            private Node<E> left;
            private Node<E> right;
            private Node( E value ) {
                this.value = value;
                left = null;
                right = null;
            }
        }

        private Node<E> root = null;
       
        /**
         * Inserts an object into this BinarySearchTree.
         *
         * @param obj item to be added
         * @return true if the object has been added and false otherwise
         */

        public boolean add( E obj ) {

            // pre-condtion:

            if ( obj == null ) {
                throw new IllegalArgumentException( "null" );
            }

            // special case:

            if ( root == null ) {
                root = new Node<E>( obj );
                return true;
            }

            // general case:

            return add( obj, root );
        }

        private boolean add( E obj, Node<E> current ) {

            boolean result;
            int test = obj.compareTo( current.value );

            if ( test == 0 ) {
                result = false;
            } else if ( test < 0 ) {
                if ( current.left == null ) {
                    current.left = new Node<E>( obj );
                    result = true;
                } else {
                    result = add( obj, current.left );
                }
            } else {
                if ( current.right == null ) {
                    current.right = new Node<E>( obj );
                    result = true;
                } else {
                    result = add( obj, current.right );
                }
            }
            return result;
        }

        /**
         * Looks up for obj in this BinarySearchTree, returns true
         * if obj is found and false otherwise.
         *
         * @param obj value to look for
         * @return true if the object has been found and false otherwise
         */

        public boolean contains( E obj ) {

            // pre-condtion:

            if ( obj == null ) {
                throw new IllegalArgumentException( "null" );
            }

            return contains( obj, root );
        }
       
        private boolean contains( E obj, Node<E> current ) {

            boolean result;

            if ( current == null ) {

                result = false;

            } else {

                int test = obj.compareTo( current.value );

                if ( test == 0 ) {

                    result = true;

                } else if ( test < 0 ) {

                    result = contains( obj, current.left );

                } else {

                    result = contains( obj, current.right );

                }
            }
            return result;
        }
       
       
        // Implement the method max()
        public E max() {

            throw new UnsupportedOperationException( "not implemented yet!" );

        }
        //implement the method  isValid
        public  boolean IsValid() {

        }
        // Implement the method min()
        public E min() {

            throw new UnsupportedOperationException( "not implemented yet!" );

        }
       
        // Implement the method depth()
        public int depth() {

            throw new UnsupportedOperationException( "not implemented yet!" );

        }
       
        // Implement the method isTwoTree()
        public boolean isTwoTree() {

            throw new UnsupportedOperationException( "not implemented yet!" );

        }

       
        public String toString() {
            return toString( root );
        }

        private String toString( Node<E> current ) {

            if ( current == null ) {
                return "()";
            }

            return "(" + toString( current.left ) + current.value + toString( current.right ) + ")";
        }

    }

Attachments:

Answers

(5)
Status NEW Posted 09 Nov 2017 01:11 PM My Price 10.00

----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y

Not Rated(0)