public List <int> duyetDFS(int s, int f, ref DO_THI dt) { List <int> str = new List <int>(); for (int i = 0; i < dt.sodinh; i++) { visited[i] = 0; /// chu f t co thay su dung au ?? coi lai di LuuVet[i] = -1; } DFS(s, ref dt); if (visited[f] == 1) { int j = f; while (j != s) { str.Add(j); j = LuuVet[j]; } str.Add(s); } else { str.Add(-1); } return(str); }
public int[] duyetBFS(int s, int f, DO_THI g) { for (int i = 0; i < g.sodinh; i++) { g.visited[i] = 0; g.LuuVet[i] = -1; } BFS(s, g); return(g.LuuVet); }
public int[] duyetDFS(int s, int f, ref DO_THI dt) { for (int i = 0; i < dt.sodinh; i++) { dt.visited[i] = 0; dt.LuuVet[i] = -1; } DFS(s, ref dt); return(dt.LuuVet); }
public void DFS(int s, ref DO_THI g) { g.visited[s] = 1; for (int i = 0; i < g.sodinh; i++) { if (g.visited[i] == 0 && g.canh[s, i] != 0) { g.LuuVet[i] = s; DFS(i, ref g); } } }
public void DFS(int s, ref DO_THI g) { visited[s] = 1; for (int i = 0; i < g.sodinh; i++) { if (visited[i] == 0 && g.canh[s, i] != int.MinValue) { LuuVet[i] = s; DFS(i, ref g); } } }
public void BFS(int s, DO_THI g) { Queue <int> q = new Queue <int>(); q.Enqueue(s); g.visited[s] = 1; while (q.Count() != 0) { s = q.Peek(); q.Dequeue(); for (int i = 0; i < g.sodinh; i++) { if (g.visited[i] == 0 && g.canh[s, i] != 0) { g.visited[i] = 1; q.Enqueue(i); g.LuuVet[i] = s; } } } }
public string[] DFSstr(int s, DO_THI g) { string[] str = new string[100]; int index = 0; for (int i = 0; i < g.sodinh; i++) { if (i == s) { continue; } else { List <int> a = duyetDFS(s, i, ref g); for (int j = a.Count - 1; j > 0; j--) { str[index] += a[j].ToString() + " "; } str[index] += a[0].ToString(); index++; } } return(str); }