Infinite loop

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
template<typename K, typename D>
void Graph<K, D>::BreadthFirst( void (*visit) (D data) )
{
	queue<Vertex<K, D> > queue;
	Vertex<K,D> temp;
	list< Vertex<K, D> >::iterator vert_itr;

	for ( vert_itr = m_list.begin(); vert_itr != m_list.end(); vert_itr++ )
	{
		vert_itr->processed = false;
	}

	queue.push( m_list.front() );

	while ( !queue.empty() )
	{
		temp = queue.front();
		queue.pop();

		if ( !temp.processed )
		{
			visit( temp.m_data );
			temp.processed = true;

			list< Edge<K,D> >::iterator edge_itr;

			for (edge_itr = temp.m_edges.begin(); edge_itr != temp.m_edges.end(); edge_itr++ )
				queue.push( *edge_itr->m_destination );
		}

	}

	for ( vert_itr = m_list.begin(); vert_itr != m_list.end(); vert_itr++ )
		vert_itr->processed = false;
}


This stays in an infinite loop for some reason. I know its because when I set temp.processed to true it doesn't actually affect the m_list's processed boolean, which holds all the vertices of my graph.

It also worked when the graph was directional, meaning that edges only connected vertices in one direction and I recently modified it so that if you insert an edge, its bidirectional.. meaning that the edges source and destination are what is passed in and when that edge is made.. Another edge is made from the destination to the source.

Any help? Thank you in advance!! =)
Last edited on
Topic archived. No new replies allowed.