-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentBST.cpp
More file actions
35 lines (28 loc) · 850 Bytes
/
StudentBST.cpp
File metadata and controls
35 lines (28 loc) · 850 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
30
31
32
33
34
35
#include "StudentBST.h"
void StudentBST::print(){
printHelper(LazyBST::getRoot());
}
void StudentBST::printHelper(TreeNode<Student*>* node){ //prints data in order
if (node== NULL)
return;
printHelper(node->left);
node->key->print();
printHelper(node->right);
}
Student* StudentBST::search(int idNum){ //special search method that searches based on the studentIDs number, because we do not want to search based on key
if(LazyBST::isEmpty())
return NULL;
TreeNode<Student*> *current = LazyBST::getRoot();
while(current->key->getID() != idNum){
if(idNum < current->key->getID()){
current = current->left;
}
else{
current = current->right;
}
if(current == NULL){
return NULL;
}
}
return current->key;
}