Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
partial fix for backpointers-> stations must be declared on the heap
  • Loading branch information
yeyun163 authored Nov 18, 2022
1 parent 5fc6c54 commit 7ab24dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions algos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ std::vector<int> testAlg(std::vector<Station> stations, std::vector<int> goal,
if (find(frontier.begin(), frontier.end(),
i->getEnd()) == frontier.end()) {
frontier.push_back(i->getEnd());
//Update predecessor pointer
//THIS IS RETURNING NULL? WHY vvvvvvvvvvvvv
stations[i->getEnd()].predecessor = &stations[top.second];
//Update predecessor pointer on the heap
//Creates memory leak, too bad!
Station* p = new Station();
p->setId(top.second);

stations[i->getEnd()].predecessor = p;
}
// //Is in frontier but with higher cost
// if (find(frontier.begin(), frontier.end(),
Expand Down
1 change: 1 addition & 0 deletions station.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Station{
void setVisited(bool inVisited) {visited = inVisited;}
void addLine(std::pair<std::string, int> line);
void addHeuristic(int val) {heuristic += val;}
void setId(int newId) {id = newId;}

// getters
int getId() const {return id;}
Expand Down

0 comments on commit 7ab24dd

Please sign in to comment.