-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbstmap.cpp
More file actions
85 lines (64 loc) · 2.56 KB
/
bstmap.cpp
File metadata and controls
85 lines (64 loc) · 2.56 KB
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
81
82
83
84
85
// Yusuf Pisan pisan@uw.edu
// 17 Jan 2021
// BST class
// Creates a BST to store values
// Uses Node which holds the data
#include "bstmap.h"
#include <cassert>
using namespace std;
// copy constructor
BSTMap::BSTMap(const BSTMap &bst) {}
// given an array of length n
// create a tree to have all items in that array
// with the minimum height (uses same helper as rebalance)
BSTMap::BSTMap(const vector<value_type> &v) {}
// destructor
BSTMap::~BSTMap() {}
// delete all nodes in tree
void BSTMap::clear() {}
// true if no nodes in BST
bool BSTMap::empty() const { return true; }
// Number of nodes in BST
int BSTMap::size() const { return 0; }
// true if item is in BST
bool BSTMap::contains(const key_type &key) const { return true; }
// If k matches the key returns a reference to its value
// If k does not match any key, inserts a new element
// with that key and returns a reference to its mapped value.
BSTMap::mapped_type &BSTMap::operator[](const key_type &k) {
assert(false && "operator[] has not been implemented");
return root->data.second;
}
// returns a vector of key-value pairs that partially match the key
// Main function used by autocomplete
// Might traverse both left and right subbranches of a node
// Example: getall("hel")
// Return: { (hello, 10), (help, 20)}
vector<BSTMap::value_type> BSTMap::getAll(const key_type &k) const {
vector<value_type> v;
return v;
}
// 0 if empty, 1 if only root, otherwise
// height of root is max height of subtrees + 1
int BSTMap::height() const { return 0; }
// height of a Node, nullptr is 0, root is 1, static, no access to 'this'
// helper function to height(), used by printVertical
int BSTMap::getHeight(const Node *n) { return 0; }
// same as contains, but returns 1 or 0
// compatibility with std::map
size_t BSTMap::count(const string &k) const { return 0; }
// inorder traversal: left-root-right
// takes a function that takes a single parameter of type T
void BSTMap::inorder(void visit(const value_type &item)) const {}
// preorder traversal: root-left-right
void BSTMap::preorder(void visit(const value_type &item)) const {}
// postorder traversal: left-right-root
void BSTMap::postorder(void visit(const value_type &item)) const {}
// balance the BST by saving all nodes to a vector inorder
// and then recreating the BST from the vector
void BSTMap::rebalance() {}
// trees are equal if they have the same structure
// AND the same item values at all the nodes
bool BSTMap::operator==(const BSTMap &other) const { return true; }
// not == to each other
bool BSTMap::operator!=(const BSTMap &other) const { return true; }