diff --git a/lectures/18_trees_I/README.md b/lectures/18_trees_I/README.md index d97b046..c0b3ca3 100644 --- a/lectures/18_trees_I/README.md +++ b/lectures/18_trees_I/README.md @@ -134,6 +134,7 @@ int count_odd (TreeNode* int) ## 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). +- A testing program is provided as well: [ds_set_main.cpp](ds_set_main.cpp). - We will use this as the basis both for understanding an initial selection of tree algorithms and for thinking about how standard library sets really work. diff --git a/lectures/18_trees_I/ds_set_main.cpp b/lectures/18_trees_I/ds_set_main.cpp new file mode 100644 index 0000000..f0e75ff --- /dev/null +++ b/lectures/18_trees_I/ds_set_main.cpp @@ -0,0 +1,32 @@ +#include +#include "ds_set_starter.h" +// #include + +int main() { + // create a set of integers + std::set numbers; + + // insert some values into the set + numbers.insert(10); + numbers.insert(5); + numbers.insert(20); + numbers.insert(15); + numbers.insert(5); // Duplicate value (won't be inserted) + + // print the elements of the set + std::cout << "The elements in the set are:" << std::endl; + for (int num : numbers) { + std::cout << num << " "; + } + std::cout << std::endl; + + // check if a specific value exists in the set + int value = 15; + if (numbers.find(value) != numbers.end()) { + std::cout << value << " is found in the set." << std::endl; + } else { + std::cout << value << " is not found in the set." << std::endl; + } + + return 0; +}