本文整理汇总了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;
}
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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;
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}