首页 > 解决方案 > 将填充的地图插入模板 bst

问题描述

所以基本上我试图用一堆不同的类型映射填充我的模板二叉搜索树(BST):

    typedef map<int, map<int, vector<WeatherLogObject>>> typeMap;.

目前这张地图将包含很多年,每年我都想创建一个节点并将其插入 bst。目前我对此有疑问,并且我遇到了我不理解的错误,因此任何指导都会被极大地接受

我的 BST 当前包含一个 Node 结构,其中包含 T 数据和左右两个 ptrs。

目前我拥有的代码是我知道它在我的主要代码中这不是很好我打算在我解决这个问题时移动它

    int main()
    {
string filePaths[125];
int counter = 0;
ifstream infile;
WeatherLog weatherLogType;
WeatherLog weatherLogTypeTemp;
vector<WeatherLog> weather;
string temp;
WeatherLog tempType;
typeMap dataMap;


infile.open("data/met_index.txt");
while (infile.peek() != EOF)
{
    infile >> filePaths[counter++];
}
for (int i = 0; i < counter; i++)
{
    infile.close();
    infile.clear();
    infile.open("data/" + filePaths[i]);
    getline(infile, temp, '\n');
    int getYear = 0;
    vector<WeatherLog> tempVector;
    int temp = 1;

    while (infile.peek() != EOF)
    {
        //get weatherlog object
        infile >> weatherLogType;
        //if its first object create map with new year
        if (getYear != weatherLogType.d.GetYear())
        {
            //for files with two months add the 12th month
            if (tempVector.empty())
            {

            }
            else
            {
                dataMap[tempVector[0].d.GetYear()][tempVector[0].d.GetMonth()] = tempVector;
                tempVector.clear();
            }
            getYear = weatherLogType.d.GetYear();
            temp = weatherLogType.d.GetMonth();
        }
        if(getYear == weatherLogType.d.GetYear()) // populate existing vector
        {
            if (temp == 12 && weatherLogType.d.GetMonth() == 1)
            {
                temp = 1;
            }
            if (temp == weatherLogType.d.GetMonth())
            {
                tempVector.push_back(weatherLogType);
            }
            else
            {
                //Check if last month is getting inputted
                if (tempVector.empty())
                {
                    temp++;
                }
                else
                {
                    dataMap[tempVector[0].d.GetYear()][tempVector[0].d.GetMonth()] = tempVector;
                    tempVector.clear();
                    temp++;
                }


            }

        }
        //Add Node for each year into bst
    }

    dataMap[tempVector[0].d.GetYear()][tempVector[0].d.GetMonth()] = tempVector;
    tempVector.clear();
}
int mid, max, year;
max = dataMap.size();
mid = max / 2;
TBST<typeMap> tree;
typeMap tempMap;
for (typeMap::const_iterator it = dataMap.begin(); it != dataMap.end(); ++it)
{
    tempMap[it->first] = it->second;
    tree.Insert(tempMap);
    tempMap.clear();
}

}

所以到最后,我希望能够从中间开始将地图添加到 bst,这样我就可以获得最佳搜索速度,并且 bst 具有正确的格式,但目前我遇到了这些错误。

    Error   C2672   'operator __surrogate_func': no matching overloaded function found  Simple Read Date    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility    1108    

    Error   C2893   Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'   Simple Read Date    c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility    1108    

抱歉,如果我可能没有添加足够的信息,请让我知道并尽快更新

标签: c++dictionarytemplatesbinary-search-tree

解决方案


推荐阅读