In this project, you will implement a binary search tree in C. You will be able to use this any of the Keil board, Windows and in Linux.
This project will require you to create
At the end, we discuss marking.
You may wish to review the installation and environment of μVision, please see the Keil board web pages. Start with the first page and the installation, and you will have to understand main to finish this project. If you are interested, there is a Hello world! that you can do in the laboratory to print to the liquid-crystal display (LCD) panel.
This project will require:
You must additionally download the type.h file and place it in the same directory with the above files.
You will implement a binary search tree data structure where
This will require you to use two structures with appropriate type definitions bst_t and bsn_t. These are provided in the header file.
You will be required to modify the bst.c file to implement the following functions to manipulate the binary search tree with n nodes and a height h:
You are provided with a skeleton bst.c file. You are welcome to create other helper functions and you are welcome to add additional fields onto any of the records as you find necessary.
To use the type bool, you will have to also use #include <stdbool.h> at the top of your source file. You will have to use #include <limits.h> to access INT_MAX and INT_MIN.
In a file called uwuserid_uwuserid_1.c, implement an instance of your structure as a local variable and add the following one hundred entries into your class.
You will require the following graphic LCD libraries:
First, you must understand how to create a skeleton main function for the Keil board.
S32 value_array[100] = { 534, 6415, 465, 4459, 6869, 4442, 5840, 4180, 7450, 9265, 23, 2946, 3657, 3003, 29, 8922, 2199, 6973, 2344, 1802, 9248, 5388, 2198, 2838, 1117, 5346, 4619, 8334, 9593, 2288, 7346, 9252, 8169, 4138, 7479, 366, 5064, 6872, -3, 8716, 8089, 15, 5337, 8700, 8128, 6673, 5395, 7772, 5792, 3379, 2438, 2184, 1176, 6083, 6572, 915, 1635, 6457, 3729, 7791, 7642, 1548, 6267, 6562, 6477, 6026, 7460, 7226, 1994, 6519, 7660, 3018, 2205, 559, 1347, 1647, 8778, 3864, 2543, 8370, 1152, 865, 860, 8735, 4782, 574, 5858, 7089, 2096, 7449, 1310, 3043, 8247, 6382, 2470, 3072, 1297, 7396, 7073, 140 };
Next, print to the LED screen the minimum and maximum entries. Then, for each of the following set of 20 entries, erase those entries from your tree and again print the minimum and maximum entries.
S32 erase_array[5][20] = { { 915, 1802, 1994, 6083, 865, 8735, 6457, 8334, 4459, 3003, 2198, 2470, 7642, 15, 7772, 1152, 29, 2096, 574, 6415}, {7396, 5858, 4442, 6872, 8128, 2838, 465, 6477, 8247, 6572, 2946, 1297, 3729, 4138, 5064, 8778, 4619, 5346, -3, 3657}, {1347, 2288, 7791, 7073, 5792, 3018, 366, 7449, 2543, 8089, 4180, 6026, 3864, 5395, 7226, 1117, 23, 7089, 1635, 6267}, {8700, 3072, 7660, 6673, 2438, 3043, 1548, 4782, 6519, 7460, 559, 860, 6562, 9593, 1647, 1310, 3379, 8716, 8922, 7450}, {9265, 6973, 8169, 5388, 140, 6869, 2344, 9252, 2184, 9248, 534, 2199, 6382, 7479, 8370, 7346, 5337, 5840, 2205, 1176} };
For your convenience, the minimum and maximum entries before each of these groups of twenty entries is erased from the tree are:
Before first group is erased -3, 9593 After first group is erased -3, 9593 After second group is erased 23, 9593 After third group is erased 140, 9593 After fourth group is erased 140, 9265 When the tree is empty 2147483647, -2147483648
To print to the screen, you will have to use the printf function. Please see formatted printing and scanning for information on the use of this function, and printing to the LCD is described together with the GLCD header files.
If the two array indicated above are declared as a local variable, both will occupy 400 bytes each and this memory will be allocated on the stack. The default stack size is 512 bytes; consequently, you have one of two options:
It is more efficient to make the arrays global, as in this case, the memory for those arrays is allocated once and resident in memory at one location; however, the data, unless declared constant, can be changed by any function using it (which, in this case, is not an issue). As a local variable, its contents must be copied onto the stack each time the function is called.
To learn about configuring the microprocessor, see configuring the Keil board.
Students will be working in groups of two and will be required to demonstrate that the function works as expected.