c ++ LNK 2019,LNK 1120错误

时间:2016-11-07 21:21:17

标签: c++

#ifndef BST_H
#define BST_H


template <class K, class D>

class TreeNode {
public:
    K key;
    D data;
    TreeNode *left;
    TreeNode *right;
    TreeNode *parentl;
    TreeNode *parentr;
    int level;
    TreeNode(K k, D d) {
        key = k;
        data = d;
        *left = null;
        *right = null;
        *parentl = null;
        *parentr = null;
        level = 0;
    }

};

#endif


//// BST.h header file

#include "BST.h"
#include <iostream>


template <class K, class D>

class BST {
public: BST() {
    *root = null;
}
private: TreeNode<K, D> *root;

public:
    bool IsEmpty() {
        if (*root == null) {
            return 1;
        }
        else return 0;
    }


    int GetHeight() {
        if (!this.IsEmpty()) {

        }
        else {
            return -1;
        }
    }

    void Inorder() {
        this->Inorder(*root);
    }

    void Preorder() {
        this->Preorder(*root);
    }

    void Postorder() {
        this->Postorder(*root);
    }

    void Levelorder() {
        this->Levelorder(*root);
    }

    void Insert(const K& key, const D& data) {
        this->Insert(*root, key, data);
    }

    void Remove(const K& key) {
        this->Remove(*root, key);
    }

    D Find(const K& key) {
        return this->Find(*root, key).data;
    }

private:
    void Inorder(TreeNode *&curr_node) {

        if (*curr_node == null) {}
        else {
            Inoder(*curr_node.left);
            std::cout << "<" << curr_node.key << "," << curr_node.data << ">" << endl;
            Inoder(*curr_node.right);
        }

    }

    void Preorder(TreeNode<K, D> *curr_node) {

        if (*curr_node == null) {}
        else {
            std::cout << "<" << curr_node.key << "," << curr_node.data << ">" << endl;
            Prenoder(*left);
            Preoder(*right);
        }

    }

    void Postorder(TreeNode<K, D> *curr_node) {

        if (*curr_node == null) {}
        else {
            Postnoder(*left);
            Postoder(*right);
            std::cout << "<" << curr_node.key << "," << curr_node.data << ">" << endl;
        }

    }

    void Levelorder(TreeNode<K, D> *curr_node) {

        if (*curr_node == null) {}
        else if (*left == null && *right == null) {
            std::cout << "<" << curr_node.key << "," << curr_node.data << ">" << endl;
        }
        else {
            Levelorder(*left);
            Levelorder(*right);
        }

    }

    TreeNode<K, D>* Find(TreeNode<K, D> *&curr_Node, const K& key) {
        if (*curr_Node == null) {
            return null;
        }
        else if (*curr_Node.key == key) {
            return *curr_Node;
        }
        else if (*curr_Node.key < key) {
            Find(*right, key);
        }
        else {
            Find(*left, key);
        }

    }

    void Insert(TreeNode<K, D> *&curr_node, const K& key, const D& data) {
        TreeNode<K, D> *tn = Find(*curr_node, key);
        if (*curr_node == null) {
            TreeNode<K, D> *ntn = TreeNode(key, data);
            root = ntn;
        }

        else if (*tn != null) {
            tn.data = data;
        }
        else if (*curr_node.key < key) {
            if (*(curr_node.right) == null) {
                TreeNode<K, D> *ntn = TreeNode(key, data);
                curr_node.right = ntn;
                ntn.parentl = curr_node;
                *ntn.level = *curr_node.level + 1;

            }
            else {
                Insert(*right, key, data);
            }
        }
        else {
            if (*(curr_node.left) == null) {
                TreeNode<K, D> *ntn = TreeNode(key, data);
                curr_node.left = ntn;
                ntn.parentr = curr_node;
                *ntn.level = *curr_node.level + 1;
            }
            else {
                Insert(*left, key, data);
            }
        }
    }

    TreeNode<K, D>*& RightMostChild(TreeNode<K, D> *&curr_Node) {
        while (*(curr_node.right) != null) {
            curr_node = curr_node.right;
        }
        return *curr_node;

    }

    void NoChildRemove(TreeNode<K, D> *&curr_node) {
        delete curr_node;
    }

    void OneChildRemove(TreeNode<K, D> *&curr_node) {
        if (*(curr_node.left) == null) {
            if (*(curr_node.parentl) == null) {
                *(curr_node.parentr).left = curr_node.right;
            }
            else {
                *(curr_node.parentl).right = curr_node.right;
            }
        }
        else {
            if (*(curr_node.parentl) == null) {
                curr_node.parentr.left = curr_node.left;
            }
            else {
                curr_node.parentl.right = curr_node.left;
            }
        }
        delete curr_node;

    }

    void TwoChildRemove(TreeNode<K, D> *&curr_node) {
        if (*(curr_node.parentl) == null) {
            curr_node.parentr.left = RightMostChild(curr_node);
        }
        else {
            curr_node.parentl.right = RightMostChild(curr_node);
        }
        delete curr_node;
    }

    void DoRemoval(TreeNode<K, D> *&curr_node) {
        if (*curr_node.left == null && *curr_node.right == null) {
            NoChildRemove(*curr_node);
        }
        else if (*curr_node.left == null || *curr_node.right == null) {
            OneChildRemove(*curr_node);
        }
        else {
            TwoChildRemove(*curr_node);
        }
    }

    void Remove(TreeNode<K, D> *&curr_node, const K& key) {
        DoRemoval(Find(*root, key));
    }



int main() {
        BST *test = new BST();
        test->Insert(1, 1.1);
        return 0;
    }


};

/// BST.cpp file

我已经为这两个错误(LNK2019,LNK 1120)挣扎了两天......

我正在搜索链接器错误并尝试了我发现的所有内容,但它仍无法正常工作

我检查了我的项目选项 - &gt;连接体 - &GT; system - &gt;子系统是控制台

我确定我的项目是Win32控制台应用程序,而我的main()存在于我的代码的最后部分。

我还尝试重新启动计算机并重新安装Visual Studio ......

它只是说不能找到main()......

如何解决这些错误?帮助我

0 个答案:

没有答案