11 Lab - Student BST
11 Lab - Student BST
Lab 11 Marks 10
Instructions
➢ Work in this lab individually. Follow the best coding practices and include comments to explain the logic where necessary.
➢ You can use your books, notes, handouts, etc. but you are not allowed to borrow anything from your peer student.
➢ Do not use any AI tool for help; doing so will be considered cheating and may result in lab cancellation and possible disciplinary
action.
➢ Test your program thoroughly with various inputs to ensure proper functionality and error handling.
➢ Show your work to the instructor before leaving the lab to get some or full credit.
class Student
{
friend class StudentBST;
private:
int id; /** student identifier (unique). */
string name; /** student name. */
float fee; /** student fee. */
Student* left; /** left subtree of a node. */
Student* right; /** right subtree of a node. */
};
class StudentBST
{
private:
Student* root; /** root of the tree. */
4. void preOrder()
• Performs a pre-order traversal of the BST and displays the details (id, name, fee) of each student.
• Calls the private helper function:
o void preOrder(Student* stree)
▪ A recursive function that performs the pre-order traversal on the subtree pointed to by stree.
• Time Complexity: 𝑂(𝑁)
5. void postOrder()
• Performs a post-order traversal of the BST and displays the details (id, name, fee) of each student.
• Calls the private helper function:
o void postOrder(Student* stree)
▪ A recursive function that performs the post-order traversal on the subtree pointed to by stree.
• Time Complexity: 𝑂(𝑁)
...
Each student’s data is separated by a blank line.
Main Function
• Implement the main() function to test the functionality of the BST. The program should:
1) Read data from the input.txt file and insert it into the BST.
2) Perform searches for specific ids and display appropriate outputs.
3) Display the BST contents using in-order, pre-order, and post-order traversals.
4) Test the deletion functionality.