Exemplo n.º 1
0
 public int begin()
 {
     Assert(G.V() >= 1);
     index = 0;
     if (index < G.V())
     {
         return(G.g [v] [index]);
     }
     return(-1);
 }
Exemplo n.º 2
0
    //使用广度搜索或者深度搜索稠密图,包含路径的寻找
    public Components(DenseGraph graph)
    {
        dgraph = graph;
        count  = 0;
        book   = new bool[dgraph.V()];
        id     = new int[dgraph.V()];
        from   = new int[dgraph.V()];
        for (int i = 0; i != dgraph.V(); i++)
        {
            id [i]   = -1;
            book [i] = false;
            from [i] = -1;
        }

//		//dfs
//		for (int i = 0; i != dgraph.V (); i++) {
//			if (!book [i]) {
//				book[i] = true;
//				from [i] = -1;
//				DenseGraphDFS (i);
//				count++;
//
//			}
//		}
//		for (int i = 0; i != dgraph.V (); i++) {
//			findPath (i);
//		}
//		Debug.Log ("图里有几个联通分量 : " + count);
        //广度优先搜索BSF
        for (int i = 0; i != dgraph.V(); i++)
        {
            if (!book [i])
            {
                DenseGraphBSF(i);
                book [i] = true;
                from [i] = -1;
                count++;
            }
        }
        Debug.Log("图里有几个联通分量 : " + count);

//		for (int i = 0; i != dgraph.V (); i++) {
//			findPath (i);
//		}
    }