Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C Programming: 5. (4pt) Suppose we want to store the ID, name, and salary of

ID: 666468 • Letter: I

Question

in C Programming:

5. (4pt) Suppose we want to store the ID, name, and salary of each employee in a binary search tree (bst). Accordingly, we defined the following node structure, read the employee information from a file, and created the binary search tree t using the ID as the key. typedef struct node( int ID; char name [201: int salary; struct node left, right nodeT, treeT: We are now interested in finding the maximum salary. Note we just want to know the maximum salary nothing else. Write a function, int FindMaxSalary (nodeT *t), that returns the maximum salary value stored in the tree t. (Note that since the tree is created based on the ID field, simply going right right... will not give you the max salary! Suppose you already have int max (int a, int b); If needed, you can use it. int FindMaxSalary (nodeT t)

Explanation / Answer

static int max(int num1, int num2) {
return (num1 > num2 ? num1 : num2); //returns max of two salaries
}

int FindMaxSalary(nodeT *t){ //recursive function
int maxSalary=0; //to store maximum salry
nodeT *temp;
temp = t;
while (temp != NULL) { //processing all nodes
maxSalary = max(maxSalary, temp->salary); //getting maximum node with salary
temp = temp->leftChild; //proecessing left chils
maxSalary = FindMaxSalary(temp); //callling recursive function
temp = temp->rightChild; //processing right chils
maxSalary = FindMaxSalary(temp); //callling recursive function
}
return maxSalary; //returning max salary
}