-
Notifications
You must be signed in to change notification settings - Fork 0
/
bstree.h
80 lines (56 loc) · 1.77 KB
/
bstree.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// bstree.h
// Specifications for BSTree class
// Authors: Yusuf Pisan & Juan Arias
//
// The BSTree class is a binary-search tree for objects of the Account class,
// which can:
// -insert an Account
// -retrieve an Account
// -display info of all stored Accounts
// -clear all stored Accounts
// -check if it is empty
#ifndef BSTREE_H
#define BSTREE_H
#include "account.h"
class BSTree {
public:
// Constructs BSTree
BSTree();
// Destroys BSTree
virtual ~BSTree();
// Inserts Account object referenced by parameter acctPtr,
// returns true if successful, false otherwise
bool Insert(Account* acctPtr);
// Points parameter acctPtr to Account object with ID given as a parameter
// returns true if found, otherwise will point to nullptr then return false
bool Retrieve(const int& ID, Account*& acctPtr) const;
// Displays info of all stored Accounts to output
void Display() const;
// Clears all stored Accounts
void Empty();
// Returns true if BSTree is empty, false otherwise
bool isEmpty() const;
private:
// Nodes of BSTree
struct Node {
// Construct Node with given pointer to Account
explicit Node(Account* acctPtr);
// Pointer to Account object
Account* acctPtr;
// Left child of current Node
Node* left;
// Right child of current Node
Node* right;
};
// Root Node of BSTree
Node* root;
// Recursive helper for Insert, uses parameter curr to traverse
bool insertNode(Node* curr, Account* newPtr);
// Recursive helper for Retrieve, uses parameter curr to traverse
bool retrieveNode(Node* curr, const int& ID, Account*& acct) const;
// Recursive helper for Display, uses parameter curr to traverse
void displayNode(Node* curr) const;
// Recursive helper for Empty, uses parameter curr to traverse
void deleteNode(Node* curr);
};
#endif