CS211 - Algorithms and Data Structures II
Tutorial 7

T Naughton, CS NUIM
Back to CS211 home


This is a tutorial on binary trees.


In order to implement an ordered binary tree to store integers, the following first steps must be taken.

  • Define a class BinTreeNode containing each node’s data and two pointers
  • Create a class OrdIntTree to maintain the tree (it will have a 'root' instead of a 'head')
  • Create a constructor and destructor for OrdIntTree and Get and Set methods for your root

    Next, we can implement some basic methods.

  • Delete the whole binary tree (recursively)
  • Recursively check if a given integer is in the tree
  • Recursively print out a list of the integers in the tree (printed list need not be in sorted order)

    Repeat of Laboratory Problem 8.2 Implement these methods.

    Of course, it will not be possible to test these methods until we are capable of adding nodes to a tree.

  • Write a method to recursively add an integer to OrdIntTree
  • Delete a given node from the tree