Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to store file entries into adjacency list
    text
    copied!<p>I have an adjacency matrix of a graph in a file.how to store this adjacency matix in a two dimensional matrix my input file looks like</p> <pre><code>e 1 36 e 2 45 e 3 74 e 4 18 e 5 36 e 6 74 e 6 45 e 6 136 e 6 36 e 6 21 e 6 18 e 7 18 e 7 116 e 7 74 e 7 99 e 7 81 e 7 135 </code></pre> <p>i need a output as adjacency list:</p> <pre><code>1--&gt;36 2--&gt;45 3--&gt;74 4--&gt;18 5--&gt;36 6--&gt;74--&gt;45--&gt;136--&gt;36--&gt;21--&gt;18 7--&gt;18--&gt;116---&gt;74--&gt;99--&gt;81--&gt;135 </code></pre> <p><br/></p> <pre><code> import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.StringTokenizer; public class Graph1 { public static void main(String[] args) throws FileNotFoundException { int linecount = 0, ec = 0; String nbin = null, cbin = null; int[][] data = null; String e = "e"; System.out.println("Graph Coloring Algorithm Test\n"); Scanner sc = new Scanner(System.in); System.out.print("Enter graph input file name: "); String newfile = sc.nextLine() + ".txt"; File file = new File(newfile); Scanner scan = new Scanner(file); while ((scan.hasNext())) { StringTokenizer t = new StringTokenizer(scan.nextLine()); if (t.nextToken().equals(e)) { ec++; nbin = scan.nextInt(); cbin = scan.nextInt(); } linecount++; for (int i = 0; i &lt; 5; ++i) for (int j = 0; j &lt; 5; ++j) { { data[nbin][cbin] = 1; } } } for (int i = 0; i &lt; 5; ++i) for (int j = 0; j &lt; 5; ++j) { { System.out.print(data[i][j]); } } } } </code></pre> <p>this code is having error .how to convert the string token to integer I how can I accept a line from file which starts with <strong>e</strong> and add it to the adjacency list.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload