CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Posts
    31

    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Shortest Path Algorithm

    Homework?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    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
  •  





Click Here to Expand Forum to Full Width

Featured