CIS 313 Lab 2 Solution

CIS 313 Lab 2 Solution

This lab involves using constructing a Binary Search Tree (BST) of numbers.


The program should do the following:

Correctly insert a node into, delete a node from and search for a node in a BST. The program should read in instructions namely : insert, delete, search , exit.

Each instruction should have the following format :

insert 4

delete 4

search 4


insert, delete and search require an argument which should be separated from the command by a single whitespace.

The program should continually accept instructions until exit is entered. On entering any instruction - the result of the operation should be displayed.

Example sequence of instructions :

insert 4

4 was inserted successfully!

insert 5

5 was inserted successfully!

delete 6

6 does not exist.

delete 5

5 deleted successfully!

search 4

Found 4!

search 3

3 does not exist.



You will need to implement the following: - a standard binary search tree data structure, supporting: insert(), delete(), and search() - a simple Node class containing three public data fields: int data, Node left, Node right - a driver class which will contain the main and other functions. I encourage you to use helper functions within your code. (Example delete could use smaller functions which handle each of the cases).

Extra Credit [10%]

If you can keep every function under 9 lines of code (and you have working code)! This includes the main() in If you managed to do this, add a comment on the top in

Powered by