不明白为什么我必须增加/减少列表迭代器才能使这个函数调用工作。有没有一种不那么复杂的方式来称呼它?参考嵌套的for循环,“insertDDNode(*(--DD_it), *(++DD_it), data[ji], data[j+1]);” 部分。
void insertDDNode(DataNode *l, DataNode *r);
vector<DataNode*> data;
list<DDNode*> DDT;
int main()
{
unsigned int n = 5;
// insert data into vector structure
data.push_back(new DataNode(0, -1, 13));
data.push_back(new DataNode(1, 0, 2));
data.push_back(new DataNode(2, 2, -14));
data.push_back(new DataNode(3, 4, 18));
data.push_back(new DataNode(4, 5, 67));
data.push_back(new DataNode(5, 6, 91));
vector<DataNode*> :: iterator it = data.begin();
list<DDNode*> :: iterator DD_it;
while(it != data.end())
{
insertDDNode(*it, *(it+1));
it++;
if((*it)->i == data.back()->i){break;}
}
DD_it = DDT.begin();
for (int i = 1; i < n; i++)
{
for (int j = i; j < n; j++)
{
insertDDNode(*(--DD_it), *(++DD_it), data[j-i], data[j+1]);
DD_it++;
}
DD_it++;
}
}
void insertDDNode(DataNode *left, DataNode *right)
{
T div_diff = (right->y - left->y) / (right->x - left->x);
DDT.push_back(new DDNode(*left, *right, div_diff));
left->r = right->l = DDT.back();
}