find-elements-in-a-contaminated-binary-tree 1.0.0
Find Elements in a Contaminated Binary Tree
Loading...
Searching...
No Matches
FindElements Class Reference
Collaboration diagram for FindElements:

Public Member Functions

 FindElements (TreeNode *root)
 
bool find (int target)
 

Private Attributes

unordered_map< int, bool > tree
 

Detailed Description

Definition at line 15 of file main.cpp.

Constructor & Destructor Documentation

◆ FindElements()

FindElements::FindElements ( TreeNode root)
inline

Definition at line 21 of file main.cpp.

22 {
23 if (!root)
24 return;
25 queue<pair<TreeNode*, int>> q; // (node, value)
26 q.push({root, 0});
27 while (!q.empty())
28 {
29 auto [node, current_val] = q.front();
30 q.pop();
31
32 tree[current_val] = true;
33 if (node->left)
34 q.push({node->left, 2 * current_val + 1});
35 if (node->right)
36 q.push({node->right, 2 * current_val + 2});
37 }
38 }
unordered_map< int, bool > tree
Definition main.cpp:18

References tree.

Member Function Documentation

◆ find()

bool FindElements::find ( int  target)
inline

Definition at line 40 of file main.cpp.

41 {
42 return tree[target];
43 }

References tree.

Field Documentation

◆ tree

unordered_map<int, bool> FindElements::tree
private

Definition at line 18 of file main.cpp.

Referenced by find(), and FindElements().


The documentation for this class was generated from the following file: