DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2007
    Posts
    2

    The main for Floyd's Algorithm Code

    Hi
    I have this Floyd's Algorithm Code, Can you help me to write the main for this function .

    #include "stdinc.h"
    #include "wdigraph.h"

    void floyd(wdigraph& G, int* dist[], vertex* mid[]) {
    // Compute a solution to the all pairs shortest path problem
    // using Floyd's algorithm. Return dist[u][v]=distance from u to v
    // and mid[u][v]=an intermediate mid-point of the shortest u-v path.

    vertex u,v,w; edge e;

    // Initialize dist and mid.
    for (u = 1; u <= G.n; u++) {
    for (v = 1; v <= G.n; v++) {
    if (u == v) dist[u][v] = 0;
    else dist[u][v] = BIGINT;
    mid[u][v] = Null;
    }
    }
    for (u = 1; u <= G.n; u++) {
    for (e = G.firstout(u); e != Null; e = G.nextout(e)) {
    v = G.head(e);
    dist[u][v] = G.w(e);
    }
    }

    // Compute distances.
    for (v = 1; v <= G.n; v++) {
    if (dist[v][v] < 0) fatal("floyd: negative cycle");
    for (u = 1; u <= G.n; u++) {
    for (w = 1; w <= G.n; w++) {
    if (dist[u][v] != BIGINT && dist[v][w] != BIGINT
    && dist[u][w] > dist[u][v] + dist[v][w]) {
    dist[u][w] = dist[u][v] + dist[v][w];
    mid[u][w] = v;
    }
    }
    }
    }
    }
    Last edited by comp_student; 01-15-2007 at 06:04 PM.

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. Microsoft's C++ bigotry
    By Phil Weber in forum .NET
    Replies: 632
    Last Post: 10-01-2003, 12:00 AM
  3. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  4. Replies: 90
    Last Post: 04-17-2001, 12:45 AM
  5. error code in JSP(please chek the code)
    By satish in forum Java
    Replies: 1
    Last Post: 09-22-2000, 09:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links