I am receiving the following compile errors:
BinarySearchTree.cpp:3: error: expected constructor, destructor, or type conversion before â<â token
BinarySearchTree.cpp:9: error: expected initializer before â<â token
BinarySearchTree.cpp:15: error: expected initializer before â<â token
BinarySearchTree.cpp:21: error: expected initializer before â<â token
Looking at my implementation, I fail to see the errors. I wonder if overloading the methods is the problem or not. Here is the rest of my code:
#ifndef BINARY_SEARCH_TREE_H
#define BINARY_SEARCH_TREE_H
#include <cstdlib>
#include <functional>
template <class T, class Key = T, class Compare = std::less<Key> >
class BinarySearchTree
{
private:
struct BinaryNode
{
T data;
Key key;
BinaryNode *left;
BinaryNode *right;
BinaryNode() : {left = NULL; right = NULL;}
BinaryNode(Key k, T i) : data(i), key(k) {left = NULL; right = NULL;}
~BinaryNode() : {delete left; delete right;}
};
BinaryNode *root;
Compare compare;
public:
BinarySearchTree();
void InsertSorted(const T& data);
void InsertSorted(const Key& key, const T& data);
private:
void InsertSortedR(const Key& key, const T& data, BinaryNode*& node);
};
#include "BinarySearchTree.cpp"
#endif
template <class T, class Key, class Compare>
BinarySearchTree<T, Key, Compare>::BinarySearchTree()
{
root = NULL;
}
template <class T, class Key, class Compare>
void BinarySearchTree<T, Key, Compare>::InsertSorted(const T& item)
{
InsertSorted(item, item);
}
template <class T, class Key, class Compare>
void BinarySearchTree<T, Key, Compare>::InsertSorted(const Key& key, const T& item)
{
InsertSortedR(key, item, root);
}
template <class T, class Key, class Compare>
void BinarySearchTree<T, Key, Compare>::InsertSortedR(const Key& key, const T& item, BinaryNode*& node)
{
// Base case: Reached end of list, or found sorted position
if (node == NULL || compare(key, node->key))
{
// Create new list node
BinaryNode *new_node = new BinaryNode(key, item);
//new_node->next = node;
// Update linked list
node = new_node;
if (root == NULL) // if list was empty, update tail
{
root = new_node;
}
}
// Recursive case:
else
{
InsertSortedR(key, item, node->right);
}
}
If anyone could please help me with this error it would be greatly appreciated. Thanks in advance.