Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dr. Gail Lange's feedback - Floyd #2

Open
dusteenie opened this issue Nov 19, 2020 · 0 comments
Open

Dr. Gail Lange's feedback - Floyd #2

dusteenie opened this issue Nov 19, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@dusteenie
Copy link
Owner

The code was excellent, except for printing out paths where there was more than one
intermediate vertex as in the case:
v0 v4 v1 v
v4 v1 v2 v3

Your code has:
public static void path(int q, int r)
{
if (P[q, r] != -1)
{
Console.Write("\nPath [" + q + ", " + r + "]\t");
path(q, P[q, r]);
Console.Write("v" + P[q, r] + " ");
path(P[q, r], r);
}

    }

whereas the code should be:

public static void path(int q, int r, int[][] P)
{
if (P[q][r] != -1)
{
path(q, P[q][r], P);
Console.Write(" v" + P[q][r] + " ");
path(P[q][r], r, P);
}
}

Adding even a line of code in a recursive function can cause different outputs from what expected.

Below is my code:
for (i = 0; i < numVertex; i++) // Output all shortest paths
for (j = 0; j < numVertex; j++)
{
if (P[i][j] != -1)
/* there is a path with intermediate vertices. Does not print if there is
just an edge between v[i] and v[j] */
{
Console.WriteLine("The shortest path between vertex " + i +
" and vertex " + j + " is:");
Console.Write("v" + i);
path(i, j, P);
Console.Write("v" + j);
Console.WriteLine();
}

                if (i != j && P[i][j] == -1 && D[i][j] != INFINITY)
                {
                    Console.WriteLine("The shortest path between vertex " + i +
                        " and vertex " + j + " is:");
                    Console.WriteLine("v" + i + "   v" + j);
                }
            }
@dusteenie dusteenie added the enhancement New feature or request label Nov 19, 2020
@dusteenie dusteenie self-assigned this Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant