SUNY Geneseo Department of Computer Science


Ordered Binary Tree Deletion, Part 2

{Date}

CSci 240, Spring 2007
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Misc

GREAT Day

Questions?

Ordered Binary Tree Deletion

Make the code a bit cleaner

    // In class OrderedTree<E>
    private E root;
    private OrderedTree<E> left, right;
	
    OrderedTree<E> delete( E value ) {
        if ( ! this.isEmpty() ) {
            if ( root == value ) {
                return this.actualDelete()
            }
            else if ( value > root ) {
                right = right.delete( value )
            }
            else {
                left = left.delete( value )
            }
        }
        else {
            return this
        }
    }

    OrderedTree<E> actualDelete() {
        if ( left.isEmpty() ) {
            return right
        }
        else if ( right.isEmpty() ) {
            return left
        }
        else {
            // copy largest value in left to this, and remove
            // that largest node in left
        }
        // Don't need secondLargest
    }
{Node to Delete, Two Children, and Parent]

Mini-assignment: fill in pseudocode for the last "else" arm above

Next

Execution time for ordered binary tree deletion

Tree traversals.


Next Lecture