Docsity

Programming Project 5: Binary Search Tree ADT | CSC 1254, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Binary Search Tree ADT CSc 1254: Programming Project# 5
Binary Search Tree ADT
Out: 11/20
Due: 12/1 by 11:59 PM
Learning Objectives
•Implementing Some BST Traversal Functions.
•Using BST Functions
•Using Recursion in Implementing BST ADT Functions
In Lecture # 21-22, we introduced an implementation of a parameterized
binary search tree abstract data type. There are several strategies for im-
plementing the BST ADT. In the code, the preorderTraverse function was
implemented. Your task in this project includes implementing two addi-
tional traversal functions: inorderTraverse and postorderTraverse. These are
pretty much analogous to preorderTraverse and they should ordinarily not
cause you much grief! You will also implement three additional recursive
functions: fullify,trim() and countOneChildNodes. Like the traversal func-
tions, these will be implemented using two functions each: a public wrapper
function and a private auxiliary function that does most of the computation.
The wrapper function should call its auxiliary function, passing it the root
of the tree.
You will have to write the main function. There are three files in this
application: A client file, usebstree.cpp, the binary search tree implemen-
tation file, bstree.cpp, and an interface for the Binary Search Tree class,
bstree.h. I have also included usebstreeexe, a working executable version
of the program.
This project has substantially more code than we have seen in this course.
However, most of it is already completed. Your task will be to complete
parts of the code I have left out. Once you complete those parts and write
the client program, the code should run correctly. In many instances, I have
implemented a function analogous to the ones you have to write. So it will
be a matter of figuring out how the ones I have written work. To make the
recursion work properly, you will need to implement a wrapper method that
provides the public interface to the client and an auxiliary private method
that actually does the bulk of the computation via recursion. Only the fol-
lowing additional functions must be added with public access. Any auxiliary
function you choose to implement must be private, for internal use only.
Duncan 1 Fall 2009
pf3
pf4

Partial preview of the text

Download Programming Project 5: Binary Search Tree ADT | CSC 1254 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Binary Search Tree ADT

Out: 11/ Due: 12/1 by 11:59 PM

Learning Objectives

  • Implementing Some BST Traversal Functions.
  • Using BST Functions
  • Using Recursion in Implementing BST ADT Functions

In Lecture # 21-22, we introduced an implementation of a parameterized binary search tree abstract data type. There are several strategies for im- plementing the BST ADT. In the code, the preorderTraverse function was implemented. Your task in this project includes implementing two addi- tional traversal functions: inorderTraverse and postorderTraverse. These are pretty much analogous to preorderTraverse and they should ordinarily not cause you much grief! You will also implement three additional recursive functions: fullify, trim() and countOneChildNodes. Like the traversal func- tions, these will be implemented using two functions each: a public wrapper function and a private auxiliary function that does most of the computation. The wrapper function should call its auxiliary function, passing it the root of the tree. You will have to write the main function. There are three files in this application: A client file, usebstree.cpp, the binary search tree implemen- tation file, bstree.cpp, and an interface for the Binary Search Tree class, bstree.h. I have also included usebstreeexe, a working executable version of the program. This project has substantially more code than we have seen in this course. However, most of it is already completed. Your task will be to complete parts of the code I have left out. Once you complete those parts and write the client program, the code should run correctly. In many instances, I have implemented a function analogous to the ones you have to write. So it will be a matter of figuring out how the ones I have written work. To make the recursion work properly, you will need to implement a wrapper method that provides the public interface to the client and an auxiliary private method that actually does the bulk of the computation via recursion. Only the fol- lowing additional functions must be added with public access. Any auxiliary function you choose to implement must be private, for internal use only.

Additional Methods

/**

  • This function traverses a binary tree in inorder
  • and calls the function visit once for each node.
  • @param visit a function that is applied
  • to the data field in every node as the tree is traversed. / void inorderTraverse(FuncType visit) const /*
  • This function traverses a binary tree in postorder
  • and calls the function visit once for each node.
  • @param visit a function that is applied
  • to the data field in every node as the tree is traversed. / void postorderTraverse(FuncType visit) const /*
  • This function removes every node that has one child from the binary search tree. */ void fullify()

/**

  • This function removes all terminal (leaf) nodes from the tree, retaining
  • all its internal nodes. */ void trim()

/**

  • This function counts the number of nodes that have either a left child or a
  • right child, but not both.
  • @return a count of the number nodes with only one child. */ int countOneChildNodes() const

Definition 1. Full Binary Tree: a binary tree in which each node has zero or two children.

Definition 2. Leaf (or terminal node): a node in a binary tree that has no children.

In this project, you will add code to bstree.h, bstree.cpp, and rewrite the main function of usebstree.cpp. You may completely remove the other functions from usebstree.cpp.

Submitting Your Work

  1. Type make clean at the system prompt to remove any object, core and executable file.
  2. All source code files you submit must have a header with the following:

/** @file filename @author your name @date 9999-99- Description: describe what this file does Course: CS1254. Logon ID: cs1254xx Project #: 5 Instructor: Duncan */

  1. Submit your assignment to the grader with the following command: ∼cs1254 dun/bin/p copy 5 This command copies everything in your prog5 directory.
  2. Once p copy is finished, check to see if all required files have been submitted: ∼cs1254 dun/bin/verify 5