0
votes

This is the code my friends and I have come up with so far after fiddling around. What we are trying to do is read in the adjacency matrix (input.txt), then create a directed graph out of it so we can search it using Depth-First Search. We want the output of our program to provide the order of visited nodes.

The java code: http://pastebin.com/bAzBadxi

The input.txt file: http://pastebin.com/r72J34uA

My question is, what do we initialize "n" to? (line 32 in the java code)

Any help will be appreciated.

2

2 Answers

1
votes

Create a vertex object before you use it.

Vertex n;    // before g.addVertex(n);

I am not validating your algorithm, just removing compiler error, if your algo is correct it should work fine

0
votes

What you are trying to solve is a problem of topological sorting.

Topological sorting

In this case, it doesn't matter what n you initialize to, you can simply use the first vertex in the adjacency matrix as the start.

And adjacency matrix (which should be a square matrix) is a legit representation of a directed graph, you can use the matrix to search the graph directly.