当前位置: 首页>>代码示例>>C#>>正文


C# Graph.Adj方法代码示例

本文整理汇总了C#中Graph.Adj方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.Adj方法的具体用法?C# Graph.Adj怎么用?C# Graph.Adj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.Adj方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: bfs

        void bfs(Graph g, int s)
        {
            Queue<int> q = new Queue<int>();
            if (sources != null)
                foreach (var ss in sources)
                {
                    q.Enqueue(ss);
                }
            q.Enqueue(s);
            marked[s] = true;
            disTo[s] = 0;
            while (q.Count != 0)
            {
                int v = q.Dequeue();
                foreach (var w in g.Adj(v))
                {
                    if (!marked[w])
                    {
                        //how do you know that you are at the next level of distance
                        //you have to somehow maintain the parent of of the node you are visiting and add one to its distance
                        //this is already recorded in edge to you just take the parent that got you to this node and get its distance and then add 1
                        disTo[w] = disTo[v] + 1;
                        q.Enqueue(w);
                        marked[w] = true;
                        edgeTo[w] = v;

                    }
                }
            }
        }
开发者ID:jw56578,项目名称:WooAlgorithms,代码行数:30,代码来源:BreadthFirstSearch.cs

示例2: dfs

 private void dfs(Graph G, int v, int u)
 {
     marked[v-1] = true;
     foreach (int w in G.Adj(v-1))
         if (!marked[w-1])
             dfs(G, w, v);
         else if (w != u) hasCycle = true;
 }
开发者ID:kaplunov93,项目名称:Algorithms,代码行数:8,代码来源:Cycle.cs

示例3: dfs

 private void dfs(Graph graph, int v)
 {
     marked[v] = true;
     count++;
     foreach (int w in graph.Adj(v))
     {
         if (!marked[w]) dfs(graph, w);
     }
 }
开发者ID:elcrespito,项目名称:ClassicAlgorightms,代码行数:9,代码来源:DepthFirstSearch.cs

示例4: Dfs

 /// <summary>
 /// depth first search from v
 /// </summary>
 /// <param name="g"></param>
 /// <param name="v"></param>
 private void Dfs(Graph g, int v)
 {
     _count++;
     _marked[v] = true;
     foreach (int w in g.Adj(v))
     {
         if (!_marked[w])
         {
             Dfs(g, w);
         }
     }
 }
开发者ID:vladdnc,项目名称:Algorithms-NET,代码行数:17,代码来源:DepthFirstSearch.cs

示例5: dfs

 void dfs(Graph g, int v)
 {
     marked[v] = true;
     id[v] = count;
     foreach (var w in g.Adj(v))
     {
         if (!marked[w])
         {
             dfs(g, w);
         }
     }
 }
开发者ID:jw56578,项目名称:WooAlgorithms,代码行数:12,代码来源:StrongComponent.cs

示例6: dfs

 void dfs(Graph g, int v)
 {
     marked[v] = true;
     foreach (var w in g.Adj(v))
     {
         if (!marked[w])
         {
             dfs(g, w);
         }
     }
     reverseOrder.Push(v);
 }
开发者ID:jw56578,项目名称:WooAlgorithms,代码行数:12,代码来源:DepthFirstOrder.cs

示例7: dfs

 void dfs(Graph g, int v)
 {
     marked[v] = true;
     foreach (var w in g.Adj(v))
     {
         if (!marked[w])
         {
             dfs(g, w);
             edgeTo[w] = v;
         }
     }
 }
开发者ID:jw56578,项目名称:WooAlgorithms,代码行数:12,代码来源:DepthFirstSearch.cs

示例8: dfs

        private void dfs(Graph graph, int v)
        {
            marked[v] = true;

            foreach (int w in graph.Adj(v))
            {
                if (!marked[w])
                {
                    edgeTo[w] = v;
                    dfs(graph, w);
                }
            }
        }
开发者ID:elcrespito,项目名称:ClassicAlgorightms,代码行数:13,代码来源:DepthFirstPath.cs

示例9: bfs

        private void bfs(Graph graph, int s)
        {
            Queue<int> queue = new Queue<int>();
            marked[s] = true;
            queue.Enqueue(s);
            while (queue.Any())
            {
                int v = queue.Dequeue();

                foreach (int w in graph.Adj(v))
                {
                    if (!marked[w])
                    {
                        edgeTo[w] = v;
                        marked[w] = true;
                        queue.Enqueue(w);
                    }
                }
            }
        }
开发者ID:elcrespito,项目名称:ClassicAlgorightms,代码行数:20,代码来源:BreadthFirstPaths.cs

示例10: Dfs

 /// <summary>
 /// depth-first search
 /// </summary>
 /// <param name="g"></param>
 /// <param name="v"></param>
 private void Dfs(Graph g, int v)
 {
     _marked[v] = true;
     _id[v] = _count;
     _size[_count]++;
     foreach (int w in g.Adj(v))
     {
         if (!_marked[w])
         {
             Dfs(g, w);
         }
     }
 }
开发者ID:vladdnc,项目名称:Algorithms-NET,代码行数:18,代码来源:CC.cs


注:本文中的Graph.Adj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。