Matrix programming
807599Mar 21 2007 — edited Mar 21 2007Hi there! I'm new to the SDN forums. Just wondering if anyone can help me with a little problem that I am having...
I'm writing a program that wil generate a random matrix of 0s and 1s. This will be used to represent a graph of some sort. The problem that I am having now is that it is ok for representing a directed graph but it is not so good for representing an undirected graph. Can anyone give me some suggestions to how this problem can be solved? Any help will be much appreciated!
Here's a bit of the code. Right now the program generates a directed graph but I want an undirected graph...
user inputs number of nodes then the following code is executed:
networkA = new int[x][y];
// Random function integrated to enter (0,1) into network
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
networkA[i][j] = zeroOne.nextInt(2);
}// Close i loop
}// Close j loop
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
System.out.print(networkA[i][j] + " ");
}
System.out.println();
Thanks in advance!