#ifndef Tournament_Tree #define Tournament_Tree #include #include // Ttree Class Used to represent binary tree objects in a tournament // The public functions are tailored to fit the needs // of conducting a tournament. class Ttree { private: struct Tnode // Basic node form { char team[13]; Tnode *left; Tnode *right; }; Tnode *Root; Tnode *Current; Tnode * Search (char *, Tnode *); // Do all work for Find void Erase (Tnode *); // Release storage for Ttree Ttree (const Ttree &); // Disable copy constructor Ttree & operator= (const Ttree &); // Disable assignment public: Ttree(void) : Root (NULL), Current (NULL) // Construct Ttree as empty { } ~Ttree(void) // Destructor erases the Ttree { Erase (Root); Current = Root = NULL; } int Find (char *); // Set Current to node holding // specified string argument void MakeRoot (char *); // Make a root node for a tree char * GetData (void); // Return team name string void JoinL (Ttree &other); // Make other a left subtree void JoinR (Ttree &other); // Make other a right subtree void Beaten (void); // You must write this function int Start (void); // Make Current the Root int Valid (void) // Make sure Current points somewhere { return Current != NULL; } }; Ttree::Tnode * Ttree::Search (char *what, Tnode *one) // PRIVATE { // Recursive search for node Tnode *temp1; // containing what; Return // pointer to node or NULL if (one == NULL) return NULL; // Based on preorder traversal else { if (strcmp(what, one->team) == 0) return one; temp1 = Search (what, one->left); if (temp1 != NULL) return temp1; else return Search (what, one->right); } } void Ttree::Erase (Tnode *P) // PRIVATE { if (P == NULL) return; // Delete all nodes in Ttree else { // rooted at P Erase (P->left); // Based on postorder traversal Erase (P->right); delete P; } } int Ttree::Find (char * what) // Public function for searching { // Set Current to node containing Current = Search (what, Root); // string what; Return indicator return Current != NULL; } void Ttree::MakeRoot (char *who) { // Form the Root node containing Root = new Tnode; // string who; set pointers to NULL strcpy (Root->team, who); Root->left = Root->right = NULL; } char * Ttree::GetData (void) // Return data value in Current node { if (Current == NULL) { cout << "Current is not valid; can't access node.\n"; exit(1); // If Current not valid, quit } return Current->team; } void Ttree::JoinL (Ttree &other) // Make other the left subtree { if (this == &other) // Make sure Ttrees are distinct { cout << "Can't join tree to self.\n"; exit (1); } Root->left = other.Root; other.Root = NULL; // Disconnect Root pointer } void Ttree::JoinR (Ttree &other) // Make other the left subtree { if (this == &other) // Make sure Ttrees are distinct { cout << "Can't join tree to self.\n"; exit (1); } Root->right = other.Root; other.Root = NULL; // Disconnect Root pointe } int Ttree::Start (void) // Set Current to Root, if possible { Current = Root; return Root != NULL; } #endif #include #include "randomft.h" void main (void) { // Write your main function here }