0

This code is aim to create a binary search tree class.

#pragma once
#include "Dictionary.h"
#include "BSTNode.h"


template <typename Key, typename E>
class BST : public Dictionary<Key, E>
{
private:
    BSTNode<Key, E> * root;
    int node_count;

    void ClearHelp(BSTNode<Key, E>*);
    BSTNode<Key, E>* InsertHelp(BSTNode<Key, E>*, const Key&, const E&);
    BSTNode<Key, E>* DeleteMin(BSTNode<Key, E>*);
    BSTNode<Key, E>* GetMin(BSTNode<Key, E>*);
    BSTNode<Key, E>* RemoveHelp(BSTNode<Key, E>*, const Key &k);
    E FindHelp(BSTNode<Key, E>*, const Key&) const;
    void PrintHelp(BSTNode<Key, E>*, int) const;
public:
    BST() { root = nullptr; node_count = 0; }
    ~BST() { ClearHelp(root); }

    void Clear() override { ClearHelp(root); root = nullptr; node_count = 0; }
    void Insert(const Key& k, const E& e) override
    {
        root = InsertHelp(root, k, e);
        node_count++;
    }
    E Remove(const Key& k) override
    {
        E tmp = FindHelp(root, k);
        if (tmp != 0)
        {
            root = RemoveHelp(root, k);
            node_count--;
        }
        return tmp;
    }

    E RemoveAny() // Delete min value
    {
        if (root != nullptr)
        {
            E temp = root->Element();
            root = RemoveHelp(root, root->key());
            return temp;
        }
        else return 0;
    }

    E Find(const Key &k) override { return FindHelp(root, k); }
    int size() override { return this->node_count; }
    void Print() const
    {
        if (root == nullptr)
            std::cout << "The BTS is empty!\n";
        else
            PrintHelp(root, 0);
    }
};

I got these errors after trying to compile the code in VS2017:

1>main.obj : error LNK2019: unresolved external symbol "private: void __thiscall BST::ClearHelp(class BSTNode *)" (?ClearHelp@?$BST@HH@@AAEXPAV?$BSTNode@HH@@@Z) referenced in function "public: virtual __thiscall BST::~BST(void)" (??1?$BST@HH@@UAE@XZ)

1>main.obj : error LNK2019: unresolved external symbol "private: class BSTNode * __thiscall BST::InsertHelp(class BSTNode *,int const &,int const &)" (?InsertHelp@?$BST@HH@@AAEPAV?$BSTNode@HH@@PAV2@ABH1@Z) referenced in function "public: virtual void __thiscall BST::Insert(int const &,int const &)" (?Insert@?$BST@HH@@UAEXABH0@Z)

1>D:\05Development\04 C_C++\C\Algorithm\BTS\Debug\BST.exe : fatal error LNK1120: 4 unresolved externals

Chengkun Li
  • 133
  • 7

0 Answers0