lec0316-BSTanalysis - MP5 available. Due 4/1 (EC due 3/18)....

Info iconThis preview shows pages 1–5. 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
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 removal and analysis http://webdiis.unizar.es/asignaturas/EDA/AVLTree/avltree.html Announcements: insert remove find traverse Binary Search Tree - Remove void BST<K,D>::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,D>::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); } Binary Search Tree - Remove void BST<K,D>::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,D>::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); } void BST<K,D>::noChildRemove(treeNode * & cRoot) { delete cRoot; cRoot = NULL; } Binary Search Tree - Remove void BST<K,D>::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);...
View Full Document

Page1 / 12

lec0316-BSTanalysis - MP5 available. Due 4/1 (EC due 3/18)....

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

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