unsigned int j = 0;
openListIterator = openListVector.begin();
while (exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].connectedExitPoint >= openListVector[j].pointId)
&& (openListIterator <= openListVector.end()))
{
// Move the iterator.
openListIterator++;
// Move the index.
j++;
}
// Insert in the vector in the required position.
listStruct objOpenListStruct;
objOpenListStruct.pointId = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].connectedExitPoint;
objOpenListStruct.weight = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].weight + exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].branchesVector[m].distance;
objOpenListStruct.parentPointId = exitPointDetailsVector[lowestWeightedPointInOpenList.pointId].exitPoint;
***********openListVector.insert (openListIterator, objOpenListStruct);
このコードはforループの下にあります。 しかし、私はイテレータの初期化を適切に行いましたが、まだ星印された行にセグメンテーションフォルトが発生しています。ベクターに挿入する
ヒント声明openListIterator <= openListVector.end()
で
ループをポストできますか? –
まず、ベクトルの間に要素を挿入したい場合、このコンテナは確かに良いオプションではありません。ベクトルは最後にデータを追加する方が効率的です。また、データを挿入すると、以前に取得されたイテレータと再割り当てが無効になります。 dequeまたはlistを間に挿入することをお勧めします – Arunmu
サイドノート:ソートされたコレクションを維持しようとしているようで、セットを使用した方がコードははるかに簡単です。 (パフォーマンスについて本当に心配しない限り) – zvrba