Default.Graph.CheckIfReachable C# (CSharp) Méthode

CheckIfReachable() public méthode

public CheckIfReachable ( ) : void
Résultat 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

        public static int Main()
        {
            Graph.flag = false;
            exitCode   = 100;

            Console.WriteLine("Test should pass with ExitCode 100");
            Console.WriteLine("Building Graph with 100 vertices...");
            Graph MyGraph = new Graph(100);

            MyGraph.BuildGraph();
            MyGraph.CheckIfReachable();

            Console.WriteLine("Deleting all vertices...");

            MyGraph.DeleteVertex();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Vertex temp = MyGraph.ReturnVfirst();

            GC.KeepAlive(temp); // will keep alive the graph till here

            Console.WriteLine("Done...");
            Graph.flag = true;  // to check if finalizers ran at shutdown or earlier
            return(exitCode);
        }
All Usage Examples Of Default.Graph::CheckIfReachable