I made an FlowChart diagram editor on Java. It It drows flowscharts and connect them each other and creates me two array. One of it shows connection nodes and lines , other shows connnecting elements eachother. I have to find all ways from starting Begin Two And . For example if I have some diamond for decision I have two seperate way ..I want to get all this ways..Which algorithms I must use?
Edit 3:SOLVED Hi again and i solved my problem my self..Here my codes .. ))
public void search(){
// System.out.print(map.length);
for(i=0;i<map.length;i++)
visit[i]=0;
visit[0]=1;
find(0,map.length-1,1);
}
public void find(int i,int d,int step){
for(int j=0;j<map.length;j++){
System.out.println(">>"+i+"->"+j);
if(visit[j]!=0 || map[i][j]==0)
continue;
if(j==d){
visit[j]=step;
OutputCycle();
visit[j]=0;
return;
}
System.out.println(""+i+" to "+j);
visit[j]=step;
find(j,d,step+1);
visit[j]=0;
}
}
public void OutputCycle(){
System.out.println("OUTPUT");
for(k=0;k<visit.length;k++){
for(int i=0;i<visit.length;i++){
if(visit[i]==k+1){
System.out.print(i);
}
}
}
System.out.println();
}
Edit 1: As I woreked on my problem I solved one part no there is also mistakes... Here my problem deeper description : I have an array that describes connection between elements
j
A B C D E
A 0 1 0 0 0
B 1 0 1 1 0
i C 0 1 0 0 1
D 0 1 0 0 1
E 0 0 1 1 0
This is my connection array ..I am trying to find all ways from starting A to E
There is 2 way
A->B->C->E
A->B->D->E
I canfind first way which searchin array from left to rigt. If I see 1 I took walu e of J and go to J`th element line in i,make that element 2 and start searchign from [i,j+1] and if reached E then send result.
But here my problem is in econd search in first line it wont see 1 and will go second line and there is first element 1 but it refers to first line and it will be loop.
Also I tried to use DFS with using backtrack but it doesnt refer to show all paths ,only one path.
And I have tried to making all below column to 0 if i foun 1 and start seaching [i,j] but in second seach it wont see anything and my arry table comes a blank table )).
I know I am missing one thing but I cant figure it ..
Edit 2:
Now I closed to solution but there is problem againg. I used this code for calculating paths from matrix
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @author Meko
*/
public class Main {
List visited = new ArrayList();
List allObjects = new ArrayList();
int map[][] = {{3, 1, 0, 0, 0},
{1, 0, 1, 1, 0},
{0, 1, 0, 0, 3},
{0, 1, 0, 0, 3},
{0, 0, 1, 1, 0}};
int i, j, k;
public Main() {
ShowArray();
System.out.println();
find(0, 0);
System.out.println();
result();
System.out.println();
afterFind();
System.out.println();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new Main();
}
public void ShowArray() {
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
System.out.print(" " + map[i][j]);
}
System.out.println("");
}
}
public void find(int sRow, int sCol) {
for (i = sRow; i < map.length; i++) {
for (j = sCol; j < map.length; j++) {
if (map[i][j] == 1) {
map[i][j] = 2;
visited.add(" " + i + " " + j);
for (k = i; k < map.length; k++) {
map[k][i] = 0;
}
find(j, i);
} else if (map[i][j] == 3) {
visited.add(" " + i + " " + j);
for (k = i; k < map.length; k++) {
map[k][i] = 0;
}
System.out.println("Founded");
map[i][j] = 2;
find(0, 0);
}
}
}
}
public void result() {
System.out.println(visited);
}
public void afterFind() {
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
System.out.print(" " + map[i][j]);
}
System.out.println("");
}
}
}
End it`s output is
3 1 0 0 0
1 0 1 1 0
0 1 0 0 3
0 1 0 0 3
0 0 1 1 0
Founded Founded Founded
[ 0 0, 0 1, 1 2, 2 4, 1 3, 3 4]
0 2 0 0 0
0 0 2 2 0
0 0 0 0 2
0 0 0 0 2
0 0 0 0 0
2 means visited and changed.. Problem is as you se in visited list it adds
00 , 01 , 12, 24 this is first path but then only 13,34 .this is because I change rest of array to 0 to not search. How can I solve this? it must 00,01,12,24 and 00,01 or 10,13,34.. Any Idea?? And I dont figure this is DFS or BFS ? or some thing else??