uniform cost search algorithm

Hey, I'm writing a UCS algorithm and came across an invalid heap error.
I have overloaded <= and < operators to work with the priority queue, but I have no idea what's wrong. I also debugged the code, and none of my containers is empty or have invalid or NULL data. The error happens after few iterations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bool Manager::UCS()
{
	priority_queue<Brick> myQueue;
	myQueue.push(myBoard->getRoot());
	mySet.insert(myBoard->getRoot().getCoorddinates());//I use the set to track the Bricks I have in my queue since there're no find function in queue.
	while (!myQueue.empty())
	{
		Brick parent = myQueue.top();
		myQueue.pop();
		mySet.erase(parent.getCoorddinates());
		if (parent.getSym() == 'G')
		{
			cout << parent.getTrackCostUpToMe();
			return true;
		}
		stack<Brick> tempStack;
		returnNeighbours(parent, &tempStack,myBoard->getNode(parent.getFatherX(),parent.getFatherY()));///Finds me all the neighbours of my brick and puts them in stack.
		while (!tempStack.empty())
		{
			tempStack.top().setTrackCostUpToMe(parent.getTrackCostUpToMe());
			if (myQueue.empty())
			{
				myQueue.push(tempStack.top());
				mySet.insert(tempStack.top().getCoorddinates());
				tempStack.pop();
			}
			else
			{
				if (mySet.find(tempStack.top().getCoorddinates()) == mySet.end())
				{
					myQueue.push(tempStack.top());/// Here's the line where I get the error
					mySet.insert(tempStack.top().getCoorddinates());
					tempStack.pop();
				}
				else tempStack.pop();
			}

		}
	}
	return false;
}
Last edited on
Topic archived. No new replies allowed.