This assignment is similar to #4 except

  • The Team information should be represented as an ascending ordered binary tree. (Keep the tree nodes in order as they are inserted.)
  • Your search for a Team Id is using a recursive binary tree traversal.
  • The command file will have a new subcommand, PPRINT, for TEAM. We will be able to pretty print the binary tree of teams. See the output below.
  • You will be provided with a driver program (cs1713p5Driver.c) (see below)
  • Your code must be created in a separate C file (p5abc123.c). (see below)
  • There is a new include file, cs1713p5.h
  • Several of the functions must be recursive: searchT, insertT, prettyPrintT, printInOrder
  • We have provided a Makefile to reduce the chances of errors typing in your gcc commands.

Input:

Team same as Programming Assignment #4; however, instead of placing it in linked list, you will put it into an ascending ordered binary tree. Some of the data may have changed.

Command Same as assignment 4 plus this new subcommand for TEAM:

TEAM PPRINT
This pretty prints the binary tree. You only have to print the Team IDs in a pretty print manner.
In the following example, notice that the right most child is printed first.
UTSA01
UNKN01
SOUTH1
NEWB01
HACK02
COM001
ALHGHT

Driver program:

You will be provided with a driver program, cs1713p5Driver.c which

1. invokes the driver's processCommandSwitches

2. invokes the driver's getTeams to read the original team information into a binary tree ordered by Team ID using your insertT function.

3. invokes your printTeams to print the original team information.

4. invokes a driver-provided processCommands which

o reads input lines from the command file until eof:

  • prints the input line
  • determines command and subcommand
  • invokes either
    • your processGameCommand to process a GAME subcommand
    • your processTeamCommand to process a TEAM subcommand

5. invokes your printTeams to print the resulting team information

6. You are also provided these functions:

Note: do not change the cs1713p5Driver.c

Your p5abc123.c code:

  • You should probably copy your p4abc123.c into a file named p5abc123.c.
  • It does the following includes:
#include < stdio.h>
#include < string.h>
#include "cs1713p5.h"
  • It must not include cs1713p5Driver.c within your p5abc123.c file. Look at the notes below on Compiling Using the make Utility.
  • Remove insertLL. We will be using insertT.
  • Remove searchLL. We will be using searchT.
  • Change printTeams:
    • Receives NodeT *pRoot instead of the linked list pHead.
    • It should still print the column heading for the table of teams; however, it should invoke printInOrder to print the tree in order.
  • Add the recursive function printInOrder which prints all the information about teams in order recursively. This is called by printTeams.
  • Change processGameCommand:
    • Receives NodeT *pRoot instead of the Node **ppHead. Notice that we are not passing the address of pRoot to this function.
    • Invokes processGame passing pRoot and game
    • Invokes processGameFix passing pRoot, game, and the two old scores.
  • Change processGame:
    • Receives NodeT *pRoot instead of the Node *pHead
    • Uses searchT to find a team in the binary tree. p1 = searchT(pRoot, game.szTeamId1);
  • Change processGameFix:
    • Receives NodeT *pRoot instead of the Node *pHead
    • Uses searchT to find a team in the binary tree.
  • Change processTeamCommand:
    • Receives NodeT **ppRoot instead of the Node **ppHead.
    • Uses searchT to find a team in the binary tree. You will have to dereference ppRoot. p = searchT(*ppRoot, team.szTeamId1);
    • The NEW subcommand uses insertT to insert a new team into the binary tree. *ppRoot = insertT(*ppRoot, team);
    • Add code for the new TEAM PPRINT subcommand. This should invoke prettyPrintT.
  • Add the function prettyPrintT which prints a binary tree by printing its right most node first. You only have to print the team IDs.
  • You must create the following routines (see the include file):
    • insertT - using the reconstruct approach, this recursively inserts a team into the ordered binary tree. This returns a pointer to the referenced subtree which is either the pointer it was passed or a pointer to a new node.
    • searchT - recursively searches for a Team Id in the ordered binary tree. If found, it returns a pointer to the node that contains it. If not found, it returns NULL.

Please review the cs1713p5.h include file.

Sample Partial Output:

Initial Teams
Id Team Name Wins Loss Fee Amt Paid Amt
Contact Name Phone Email
ALHGHT Cake Eaters 4 4 175.00 100.00
E Z Street (210)555-6666 sliverspoon@xyz.com
COM001 Comm Eagles 7 1 150.00 75.00
Mae King (210)555-2222 maeking@xyz.com
HACK02 Hackers 3 5 150.00 75.00
Tom E Gunn (210)555-5555 cyber@gmail.com
NEWB01 River Rats 0 8 120.00 75.00
Rock D Boat (210)555-4444 riverrat@xyz.com
SOUTH1 Slam Dunk 5 3 120.00 75.00
Jerry Tall (210)555-3333 slamdunk@gmail.com
UNKN01 Org New Blk 1 7 150.00 50.00
Bob Wire (210)555-1234 bobwire@xyz.com
UTSA01 Armadillos 8 0 150.00 80.00
Jean E Us (210)555-1111 utsa@xyz.com
TEAM PPRINT
UTSA01
UNKN01
SOUTH1
NEWB01
HACK02
COM001
ALHGHT
GAME RESULT UTSA01 NEWB01 55 12
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.