adding test program

This commit is contained in:
Jidong Xiao
2025-03-18 13:43:28 -04:00
committed by JamesFlare1212
parent 2d827df9ab
commit 2b7a3f5b7f
2 changed files with 33 additions and 0 deletions

View File

@@ -134,6 +134,7 @@ int count_odd (TreeNode<int>* int)
## 18.7 ds_set and Binary Search Tree Implementation ## 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 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 - 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. about how standard library sets really work.

View File

@@ -0,0 +1,32 @@
#include <iostream>
#include "ds_set_starter.h"
// #include <set>
int main() {
// create a set of integers
std::set<int> 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;
}