Server IP : 172.16.15.8 / Your IP : 3.135.208.189 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/jwmccreary/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// stutreeclient.cpp - test client for gradetree class #include "stutree.h" #include <iostream> using namespace std; //--------------------------------------------------------------------------- int main() { Gradetree grades, other; int S, N, C, L, NL, H; float A; bool SI; // First, add some unique grades grades.Insert (80); grades.Insert (75); grades.Insert (66); grades.Insert (78); grades.Insert (88); grades.Insert (86); grades.Insert (94); grades.Insert (92); grades.Insert (50); grades.Insert (68); grades.Insert (70); grades.Insert (98); grades.Insert (96); grades.Insert (97); //Nodes for the other tree other.Insert (80); other.Insert (75); other.Insert (66); other.Insert (78); other.Insert (88); other.Insert (86); other.Insert (94); other.Insert (92); other.Insert (50); other.Insert (68); other.Insert (70); other.Insert (98); other.Insert (96); other.Insert (97); // Display picture of tree cout << "\n\nAfter adding 80,75,66,78,88,86,94,92,50,68,70,98,96,97"; cout << "\nSideways 'picture' of the tree:\n\n"; grades.TreePicture (); //outputs the sum of the grades S = grades.SumGrades(); cout << "The Sum of the Grades is: " << S << "\n"; //outputs the number of grades N = grades.NumGrades(); cout << "The Num of the Grades is: " << N << "\n"; //outputs the grade average A = grades.AvgGrade(); cout << "The Average of the Grades is: " << A <<"\n"; //outputs the number of nodes in the tree C = grades.NodeCount(); cout << "The number of nodes is: " << C << "\n"; //outputs the number of nodes that are leaves L = grades.LeafCount(); cout << "The number of leaves is: " << L << "\n"; //outputs the number of nodes that are not leaves NL = grades.NonLeafCount(); cout << "The number of nodes that are not leaves is: " << NL << "\n"; //outputs the height of the tree H = grades.Height(); cout << "The Height of the tree is: " << H << "\n"; //outputs othertree cout << "\nSideways 'picture' of the other tree:\n\n"; other.TreePicture (); //outputs whether or not trees are similar if(grades.SimilarTrees(other) == true) cout << "\n\nThe Trees are similar.\n"; else cout << "\n\nThe Trees are not similar.\n"; //Add some new nodes to the other tree other.Insert (25); other.Insert (47); other.Insert (32); //outputs othertree once again cout << "\nSideways 'picture' of the other tree:\n\n"; other.TreePicture (); //outputs whether or not trees are similar if(grades.SimilarTrees(other) == true) cout << "\n\nThe Trees are similar.\n"; else cout << "\n\nThe Trees are not similar.\n"; // Next, add some duplicate grades grades.Insert (88); grades.Insert (50); grades.Insert (94); // Make sure tree structure is still the same cout << "\nSideways 'picture' of the tree:\n\n"; grades.TreePicture (); // Display the traversals cout << "\nTree Traversals:"; cout << "\n PRE: "; grades.Preorder (); cout << "\nPOST: "; grades.Postorder (); cout << "\n IN: "; grades.Inorder (); // Now delete key nodes and display picture after each grades.Delete (75); cout << "\n\nAfter deleting 75 (Case 3)\n\n"; grades.TreePicture (); grades.Delete (98); cout << "\n\nAfter deleting 98 (Case 2)\n\n"; grades.TreePicture (); grades.Delete (86); cout << "\n\nAfter deleting 86 (Case 1)\n\n"; grades.TreePicture (); grades.Delete (97); cout << "\n\nAfter deleting 97 (Case 1)\n\n"; grades.TreePicture (); cout << "\n\n"; //N = grades.NumGrades(); //cout << N << "\n"; //A = grades.AvgGrade(); //cout << A << "\n"; //C = grades.NodeCount(); //cout << C << "\n"; return 0; }