|
-
March 15th, 2007, 09:47 AM
#1
Shortest Path Algorithm
Code:
public void unweighted( String startName )
{
clearAll( );
Vertex start = vertexMap.get( startName );
if( start == null )
throw new NoSuchElementException( "Start vertex not found" );
Queue<Vertex> q = new LinkedList<Vertex>( );
q.add( start ); start.dist = 0;
while( !q.isEmpty( ) )
{
Vertex v = q.remove( );
for( Edge e : v.adj )
{
Vertex w = e.dest;
if( w.dist == INFINITY )
{
w.dist = v.dist + 1;
w.prev = v;
q.add( w );
}
}
}
}
For the unweighted shortest path algorithm, how would you change this code so that it searches for the minimum-cost vertex as a sequential scan of the vertex table? Thanks.
-
March 15th, 2007, 09:48 AM
#2
Re: Shortest Path Algorithm
Homework?
Regards,
Paul McKenzie
-
March 15th, 2007, 10:14 PM
#3
Re: Shortest Path Algorithm
Wrong forum, too.
The posted code isn't even C++.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|