0% found this document useful (0 votes)
8 views

DSA Assignment 3

DSA Assignment 3

Uploaded by

umar playsyt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DSA Assignment 3

DSA Assignment 3

Uploaded by

umar playsyt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment 3

Data Structures and Algorithms

Write a program for binary search tree that satisfies the following requirements:

1. User will be allowed to insert Integer values into the BST.


2. User will be allowed to delete data from the BST.
3. Duplicate values will be handled with a count value in the node. Every
time a duplicate value is added, the count value will be incremented.
4. The user will be allowed to print the tree on the screen using pre-order, in-
order, and post-order traversals
5. The user will be allowed to search the tree for a value. If the value is
found, the user will be informed that the value was in the tree and will be
told the number of comparisons needed to find the value. In addition, the
user will be informed about the level of the node in which information was
found (you are not allowed to keep this information in the node, and it
must be determined at run time). If the value is not found, the user will be
told that the value was not in the tree and the number of comparisons that
were made.
6. All dynamically allocated memory must be explicitly freed

The binary tree node will consist of an integer data value, a count value plus a
left and right pointer (all of which are private). The bst class will maintain a
binary search tree composed of zero or more binary tree nodes. The bst class
will maintain a private root_ptr variable using several public member functions
that represent the interface to the data structure.

The bst class must provide (at minimum):


1. a default constructor
2. a destructor
3. an insert function that takes a single int as a parameter
4. a delete function that takes a single int as a parameter and does the
following:
a. if the data is found then reduces its count by 1. If it becomes 0 then
it deletes that node. If the data is not found, then nothing is done.
b. It displays an appropriate message and then returns.
5. an inorder function that prints the tree using an in-order traversal
6. a count function that returns the count value of a specified key
7. a searchtree function that takes three parameters and returns a bool value
(the first parameter is the value to find, the second parameter will hold the
number of comparisons made, and the third parameter will hold the level
of the node)

You might also like