I have my BST built and it's working. But the only thing that doesn't seem to be working are the following functions which I built to print out the maximum and minimum of the gpa's (each tree node contains a struct of an ID, gpa, and age). It prints out the same thing for both and it seems neither are right.
void IntBinaryTree::displayMaxandMin(TreeNode *nodePtr)
{
double min, max;
min = findMin(nodePtr);
cout << "The lowest gpa in the class is: "<< min<<endl;
max = findMax(nodePtr);
cout << "The highest gpa in the class is: "<< max<<endl;
}
double IntBinaryTree::findMin(TreeNode *nodePtr)
{
double min = 1000.00;
if (nodePtr)
{
findMin(nodePtr->left);
cout << nodePtr->student.gpa<<endl;
if (nodePtr->student.gpa < min)
min = nodePtr->student.gpa;
findMin(nodePtr->right);
}
return min;
}
double IntBinaryTree::findMax(TreeNode *nodePtr)
{
double max = 0.00;
if (nodePtr)
{
findMax(nodePtr->left);
cout << nodePtr->student.gpa<<endl;
if (nodePtr->student.gpa > max)
max = nodePtr->student.gpa;
findMax(nodePtr->right);
}
return max;
}