
Computer Science II — CSci 1200
Lecture 17 — Trees, Part 2
Review from Lecture 16
•Binary trees and binary search trees. They have a close tie to recursion.
•Tree nodes
•Basic tree algorithms: traversals
•Overview of tree implementation of cs2set class.
•Implementation of begin and find.
We will complete the discussion of begin and find in this lecture.
Review in more detail: cs2set class overview
•The classes are templated.
•There is an auxiliary TreeNode class
•The only member variables of the cs2set class are the root pointer and the size
(number of tree nodes).
•The iterator class is declared internally, and is effectively a wrapper on TreeNode
pointers.
–Note that operator* returns a const reference because the keys may not be
changed.
–The increment and decrement operators are missing. These will be discussed
more later in the lecture.
•The main public member functions just call a private (and often recursive) member
function (passing the root pointer) that does all of the work.
•Because the class stores and manages dynamically allocated memory, it must provide
a copy constructor, an operator=, and a destructor in order to work correctly.
Today’s Lecture
•cs2set operations: insert, destroy, printing, erase
•Tree height
•Increment and decrement operations on iterators
•Limitations of our implementation