DefaultNamespace.Graph.CheckIfReachable C# (CSharp) Method

CheckIfReachable() public method

public CheckIfReachable ( ) : void
return void
	public void CheckIfReachable() {
		int[] temp = new int[Nodes];
		Vertex t1 = Vfirst;
		
		Console.WriteLine("Making all vertices reachable...");
		while(t1 != null) {
			for(int i=0;i<t1.Num_Edges;i++) {
				if(temp[t1.Adjacent[i].Name] == 0)
					temp[t1.Adjacent[i].Name]=1;
			}
			t1 = t1.Next;
		}

		for(int v2=0;v2<Nodes;v2++) {
			if(temp[v2]==0) {  //this vertex is not connected
				DateTime time = DateTime.Now;
				Int32 seed = (Int32)time.Ticks;
				Random rand = new Random(seed);
				int v1;
				while((v1 = rand.Next(0,Nodes))==v2);     //select a random node, also avoid self-loops
				BuildEdge(v1,v2);
				temp[v2]=1;
			}
		}
		
	}
	

Usage Example

Example #1
0
        public static void Main()
        {
            Console.WriteLine("Building Graph with 800 vertices...");
            Graph MyGraph = new Graph(800); // graph with 800 nodes

            MyGraph.BuildGraph();

            Console.WriteLine("Checking if all vertices are reachable...");
            MyGraph.CheckIfReachable();

            //Console.WriteLine("Printing the Graph...");
            //MyGraph.PrintGraph();

            Console.WriteLine("Deleting a random vertex...");
            MyGraph.DeleteVertex();

            //MyGraph.PrintGraph();

            Console.WriteLine("Done");
            Environment.ExitCode = (0);
            Console.WriteLine("Test Passed");
        }
All Usage Examples Of DefaultNamespace.Graph::CheckIfReachable