-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBST.cpp
More file actions
29 lines (29 loc) · 863 Bytes
/
Copy pathBST.cpp
File metadata and controls
29 lines (29 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "BST.h"
#include <iostream>
Node* BST::insert(Node* root, Species key) { // insert node into tree
if (root == nullptr) {
Node* t = new Node(key);
return t;
}
if (key.GetName() > root->s.GetName())
root->right = insert(root->right, key);
else
root->left = insert(root->left, key);
return root;
}
Node* BST::search(Node* root, string name) { // find node based on name
if (root == nullptr || root->s.GetName() == name) {
return root;
}
if (name > root->s.GetName())
return search(root->right, name);
else
return search(root->left, name);
}
void BST::InOrder(Node* root) { // inorder traversal of tree
if(root != nullptr) {
InOrder(root->left);
string name = root->s.GetStatus();
InOrder(root->right);
}
}