lec0314-BSTremove - MP5 available. Due 4/1 (EC due 3/18)....

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MP5 available. Due 4/1 (EC due 3/18). Today: Binary Search Trees Announcements: A Binary Search Tree (BST) is a binary tree, T, that: • __________, OR • T = {r, T L , T R } and x ∈ T L → _______________ x ∈ T R → _______________ and Binary Search Tree ADT: insert remove find traverse template <class K, class D> class BST{ public: // see ADT private: struct treeNode{ D data; K key; treeNode * left; treeNode * right; }; treeNode * root }; Binary Search Tree - Find ________________________ (treeNode * cRoot, const K & key) { if (cRoot == NULL) else if (cRoot->key == key) else if else } Binary Search Tree - Insert ________________________ (treeNode * cRoot, const K & key, const D & data){ if (cRoot == NULL) else if (cRoot->key == key) else if else } Binary Search Tree - Remove (recursive skeleton) ______ _________ (treeNode * cRoot, const K & key) { if (cRoot == NULL) else if (cRoot->key == key) else if else } Binary Search Tree - Remove T.remove(37); T.remove(10); T.remove(13); Binary Search Tree - Remove void BST<K>::remove(treeNode * & cRoot, const T & d) { if (cRoot == NULL) return; // no op… key not found else if (cRoot->key == d) doRemoval(cRoot); else if (d < cRoot->key) remove(cRoot->left,d); else remove(cRoot->right,d); } void BST<K>::doRemoval(treeNode * & cRoot) { if ((cRoot->left == NULL) && (cRoot->right == NULL)) noChildRemove(cRoot); else if ((cRoot->left != NULL) && (cRoot->right != NULL)) twoChildRemove(cRoot); else oneChildRemove(cRoot); }...
View Full Document

This note was uploaded on 01/26/2012 for the course CS CS 225 taught by Professor Heeren during the Spring '09 term at University of Illinois, Urbana Champaign.

Page1 / 12

lec0314-BSTremove - MP5 available. Due 4/1 (EC due 3/18)....

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online