SUNY Geneseo Department of Computer Science
{Date}
CSci 240, Spring 2007
Prof. Doug Baldwin
GREAT Day
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
}
Mini-assignment: fill in pseudocode for the last "else" arm above
Execution time for ordered binary tree deletion
Tree traversals.