将填充的地图插入模板bst

时间:2019-05-25 04:59:15

标签: c++ dictionary templates binary-search-tree

所以基本上,我想用一堆不同类型的地图填充模板二进制搜索树(BST):

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

当前,此地图将包含一堆年份,并且每年我要创建一个节点并将其插入到bst中。目前,我对此有疑问,并且遇到了我不理解的错误,因此任何指导都将被接受

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

当前我拥有的代码是这个,我知道它在我的主代码中是不好的,我计划在解决此问题后再移动它

    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();
}

}

所以到最后,id希望能够从中间开始将地图添加到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    

抱歉,如果我还没有添加足够的信息,请尽快告知我,并且请尽快更新

0 个答案:

没有答案