Note that there are some explanatory texts on larger screens.

plurals
  1. POTaking string and putting it into an array Java
    primarykey
    data
    text
    <p>I am making a java program that will Use “brute force” by generating all possible permutations and checking if any are matching. Example: If G1 = “0-1 0-2 1-2 1-3 2-3” and G2 = “1-3 2-0 0-3 1-2 1-0” then the permutation 0123 → 2310 does not match, but 0123 → 2013 does match.</p> <p>I need to make a graph class the represents the graph as a 2-D boolean array and has member functions to check if 2 vertices are an edge and to print a graph. The constructor should use the above string representing a list of edges. </p> <p>I need to know how I would take the string in that format and put it in an array. </p> <p>Overall, I want to find out if the two graphs are isomorphic. </p> <p>The code below is the permutation generator. </p> <pre><code>// Generator of all permutations of: 0,1,2,...,n-1 public class PermutationGenerator { // private data private int[] perm; private boolean first; // constructor public PermutationGenerator (int n) { perm = new int [n]; first = true; } public int[] next () { int n = perm.length; // starting permutation: 0 1 2 3 ... n-1 if (first) { first = false; for (int i = 0 ; i &lt; n ; i++) perm [i] = i; return perm; } // construct the next permutation // find largest k so that perm[k] &lt; perm[k+1]; if none, finish int i, j, k, l; for (k = n - 2 ; k &gt;= 0 &amp;&amp; perm [k] &gt;= perm [k + 1] ; k--) ; if (k &lt; 0) return null; // no more // find largest l so that perm[k] &lt; perm[l] for (l = n - 1 ; l &gt;= 0 &amp;&amp; perm [k] &gt;= perm [l] ; l--) ; // swap perm[k] and perm[l] swap (perm, k, l); // reverse perm[k+1]...perm[n-1] for (i = k + 1, j = n - 1 ; i &lt; j ; i++, j--) swap (perm, i, j); return perm; } // swap a[i] and a[j] private static void swap (int a[], int i, int j) { int temp = a [i]; a [i] = a [j]; a [j] = temp; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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