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
|
struct bst_node
{
string value;
T key;
bst_node<T> *left;
bst_node<T> *right;
bst_node<T> *parent;
};
template <class T>
void bst<T>::insert(string val, T key1)
{
bst_node<T> *nova = new bst_node<T>(val, key1);
bst_node<T> *temp = nodefinder(key1, root);
if (temp != NULL) {
temp->value = val;
} else {
nodein(val, key1, *&root, NULL);
}
}
template <class T>
void bst<T>::nodein(string val, T key1, bst_node<T> *&nova) {
if (nova == NULL) {
nova = new bst_node<T>(val, key1);
} else {
if (key1 < nova->key) {
nodein(val, key1, nova->left, nova);
} else {
nodein(val, key1, nova->right, nova);
}
}
}
|