CS 311 Fall 2020  >  Project 7


CS 311 Fall 2020
Project 7

Project 7 is due at 5 pm Monday, November 16. It is worth 60 points.

Procedures

This is, optionally, a group assignment. You may work in a group of 2 or 3, if you wish. Each group only needs to turn in a single copy of the assignment. Under normal circumstances, each group member will receive the same grade on the assignment.

Turn in answers to the exercises below on the UA Blackboard Learn site, under Project 7 for this class.

If you work in a group:

Exercises (60 pts total)

Exercise A — Treesort

Purpose

In this exercise, you will implement the Treesort algorithm. This will require at least a partial implementation of a Binary Search Tree, including insertion and inorder traversal, and use of iterators.

Instructions

This project may be done individually or in a group of 2 or 3.

Write a C++ function template that sorts a given range using the Treesort algorithm. Be sure to follow the coding standards. All standards now apply!

Slides & Skeleton File

Thoughts on writing function treesort can be found in the lecture slides for Monday, November 9.

I have provided an incomplete “skeleton” version of treesort.h; this is in the Git repository. You may use this as the basis for your own work, if you wish. This is not required.

Test Program & Grading

A test program is available: treesort_test.cpp. If you compile and run the test program (unmodified!) with your code, then it will test whether your code works properly.

The test program requires doctest.h, the header for the doctest unit-testing framework, version 2.

Do not turn in the test program or the doctest framework.

Note: The test program does not check whether you actually use a Binary Search Tree. However, code that does not at least appear to make an attempt at using a Binary Search Tree will not be graded.

Notes on Iterators

Forward Iterators

A forward iterator is guaranteed to allow the following operations:

In particular, you can do this:

for (FDIter it = first; it != last; ++it)
{
    doSomething(*it);
}

You may dereference a forward iterator any number of times without changing the iterator. You may not decrement a forward iterator. You also may not add a number to a forward iterator or subtract two forward iterators; however, std::advance and std::distance may be used to perform these operations.

Finding the Value Type

It is likely that you will need to figure out what the value type is, that is, what type an iterator of type FDIter points to. You can use code like the following (std::iterator_traits is declared in header <iterator>).

[C++]

using Value = typename iterator_traits<FDIter>::value_type;

You can then use Value as you would any other type. In particular, you could do something like the following

[C++]

auto p = make_shared<BSTreeNode<Value>>(item, nullptr, nullptr);

... assuming, of course, that you have an appropriate class template named BSTreeNode, which has a 3-parameter constructor.

See treesort.h, in the Git repository, for example code that determines and uses the value type of an iterator,