Binary Search Tree Operations

Binary Search Tree Operations - Lecture 16: Binary Tree...

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

View Full Document Right Arrow Icon
1 Lecture 16: Binary Tree Operations PIC 10B Todd Wittman The TreeNode Class template <typename T> class TreeNode { public: TreeNode(T value); T getValue() const; template <typename T> friend class Tree; private: T data; TreeNode<T>* left; TreeNode<T>* right; }; template <typename T> TreeNode<T> :: TreeNode (T value) { data = value; left = NULL; right = NULL; } template <typename T> T TreeNode<T> :: getValue() const { return data; } data left right Note : A more efficient "doubly-linked" implementation would include a parent node.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 The Tree Class template <typename T> class Tree { public: Tree(); ~Tree(); TreeNode<T>* getRoot() const; TreeNode<T>* find (T value); TreeNode<T>* parent(TreeNode<T>* child); void insert (T value); void erase (TreeNode<T>* pos); **Other functions: findMaximum, print, size, height, . ..** private: TreeNode<T>* root; }; Note we use a lot of TreeNode pointers. Our main routine will have to
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Binary Search Tree Operations - Lecture 16: Binary Tree...

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

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