Update README.md
Updated the 18.6 exercise with the code written in class during lecture.
This commit is contained in:
@@ -104,10 +104,34 @@ public:
|
||||
1. Write a templated function to find the smallest value stored in a binary search tree whose root node is pointed
|
||||
to by p.
|
||||
|
||||
2. Write a function to count the number of odd numbers stored in a binary tree (not necessarily a binary search
|
||||
```cpp
|
||||
template <class T>
|
||||
const T& find_smallest (TreeNode <T>* root)
|
||||
{
|
||||
if(root->left == NULL)
|
||||
{
|
||||
return root->value;
|
||||
}
|
||||
return find_smallest(root->left);
|
||||
}
|
||||
```
|
||||
|
||||
3. Write a function to count the number of odd numbers stored in a binary tree (not necessarily a binary search
|
||||
tree) of integers. The function should accept a TreeNode<int> pointer as its sole argument and return an
|
||||
integer. Hint: think recursively!
|
||||
|
||||
```cpp
|
||||
int count_odd (TreeNode<int>* int)
|
||||
{
|
||||
if(node == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return abs(node->value % 2) + count_odd(node->left) + count_odd(node->right);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## 18.7 ds_set and Binary Search Tree Implementation
|
||||
|
||||
- A partial implementation of a set using a binary search tree is provided in this [ds_set_starter.h](ds_set_starter.h). We will continue to study this implementation in Lab 10 & the next lecture.
|
||||
|
||||
Reference in New Issue
Block a user