Efficiently Processing Temperature Samples
Your task is to create an application for the scientific processing of temperature samples. Scientists from all around the world will use this application.
The functional requirements from the scientists are as follows:
It is important to understand that the application will constantly receive data. For example, the scientist may add some data, perform some queries, add more data, perform some more queries, and so on. Using an array to solve the problem and constantly sorting or checking all the elements to answer a query every time will be too slow. One of the main requirements of the scientists is that the application must be fast and responsive. To address this point, you use your handy binary search tree implementation.
The tasks will be tested automatically based on the messages displayed from your functions. Make sure not to have any typos, extra spaces, or newlines (or missing spaces or newlines) inside the messages, or the tests will fail.
Note: If some tests fail and you want to perform some debugging, feel free to display the tree using the
printBST
function. Just know that as soon as you do this, the tests will fail because the output will not match. It is fine, but do not forget to remove the debug messages after you fix the bugs. Otherwise, the tests will still not work.
Note: If the tree is big (more than 100-150 values), the output of
printBST
may break, as there is not enough space in the console to display the whole tree.
Finally, for testing purposes, the tester will do the following:
testStarted
function before performing any tests. It allows you to perform any initializations if you need them. It is acceptable to leave this function empty.testEnded
function after performing the last test. It allows you to perform any cleanup and free the memory.Lastly, since float values can be unstable, to ensure that your output matches the tests, print the floats using %.1f
(only one decimal).
To use your binary search tree implementation, you will need a compareFloat
function (among other things) to tell the BST how to order the values. We suggest you use the following comparison function to ensure no mismatch between your output and the reference solution. In short, this function considers two floats equal if their difference is less than 0.01
.
#define FLOAT_DELTA 0.01
int compareFloat(void* a, void* b)
{
float* ptr1 = (float*)a;
float* ptr2 = (float*)b;
return (fabs(*ptr1 - *ptr2) < FLOAT_DELTA) ? 0 : *ptr1 - *ptr2 > 0 ? 1 : -1;
}
Check the console to see the output of your code.
Here is a complete solution. Please check the reference solution only as a last resort after you did your best to solve the tasks on your own.