The reason why currentNode changes get reflected in parent, is because I am assigning the address to parent. so any changes get reflected. However, now I create currentNode, as a pointer, it will have different address. and have declared the rest as pointers as well
NavigationNode *startNode;
startNode->x = START_X;
startNode->y = START_Y;
startNode->g = 0;
startNode->f = 0;
vector<NavigationNode*> openList;
openList.push_back(*startNode);
NavigationNode *currentNode = new NavigationNode;
while (!openList.empty())
{
// sort the vector by increasing F values, so the lowest F values will be at the first location
// sort(openList.begin(), openList.end(), compareByF);
for (auto i = openList.begin(); i != openList.end(); ++i){
if (i == openList.begin() || (*i)->f <= currentNode->f){
currentNode = (*i);
}
}
for (int i = 0; i < numberOfDirections; i++)
{
NavigationNode *nextNode = new NavigationNode;
nextNode->x = xChange;
nextNode->y = yChange;
// some logic operations
// assign the currentNode to the parentNode
nextNode->parent = currentNode;
nextNode->value = map[xChange][yChange];
openList.push_back(nextNode);
} // end for loop
}// end while loop