I have tried implementing depth first search in c# but I am not exactly sure how to do this the distributed computing way. If you guys can help me out in this i would be really grateful :) You can find my DFS code below
public class DFS
{
static List<string> traversedList = new List<string>();
static List<string> parentList = new List<string>();
public static void Main(string[] args)
{
int N = 100;
int M = N * 4;
int P = N * 16;
Stack newstack = new Stack();
List<string> global_list=new List<string>();
StreamReader file = new StreamReader("my input file");
string text = file.ReadToEnd();
string[] lines = text.Split('\n');
string[][] array1 = new string[lines.Length][];
for (int i = 0; i < lines.Length; i++)
{
lines[i] = lines[i].Trim();
string[] words = lines[i].Split(' ');
array1[i] = new string[words.Length];
for (int j = 0; j < words.Length; j++)
{
array1[i][j] = words[j];
}
}
StreamWriter sr = new StreamWriter(args[0]);
for (int i = 0; i < array1.Length; i++)
{
for (int j = 0; j < array1[i].Length; j++)
{
if (j != 0 )
{
sr.Write(array1[i][0] + ":" + array1[i][j]);
Console.WriteLine(array1[i][0] + ":" + array1[i][j]);
sr.Write(sr.NewLine);
}
}
}
int start_no = Convert.ToInt32(args[args.Length-1]);
traversedList.Add(start_no.ToString());
parentList.Add("root");
dfs(array1, start_no);
for (int z = 0; z < traversedList.Count; z++)
{
Console.WriteLine(traversedList.ElementAt(z) + " "+parentList.ElementAt(z)+" "+(z+1));
}
Console.ReadLine();
}
private static void dfs(string[][] array, int point)
{
for (int z = 1; z < array[point].Length; z++)
{
if ((!traversedList.Contains(array[point][z])))
{
traversedList.Add(array[point][z]);
parentList.Add(point.ToString());
dfs(array, int.Parse(array[point][z]));
}
}
return;
}
}