本文整理汇总了C++中AdjacencyList::GetNeighbors方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjacencyList::GetNeighbors方法的具体用法?C++ AdjacencyList::GetNeighbors怎么用?C++ AdjacencyList::GetNeighbors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdjacencyList
的用法示例。
在下文中一共展示了AdjacencyList::GetNeighbors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Explore
void Explore(const AdjacencyList& graph, Vertex u,
vector<bool>& visited, vector<int>& cc) {
visited[u] = true;
for (const Neighbor& neighbor : graph.GetNeighbors(u)) {
Vertex v;
double ignored_cost;
std::tie(v, ignored_cost) = neighbor;
if (!visited[v]) {
cc[v] = cc[u];
Explore(graph, v, visited, cc);
}
}
}
示例2: Reverse
AdjacencyList Reverse(const AdjacencyList& graph) {
size_t n = graph.NumVertices();
AdjacencyList rg(n);
for (Vertex u = 0; u < n; ++u) {
for (const Neighbor& neighbor : graph.GetNeighbors(u)) {
Vertex v;
double ignored_cost;
std::tie(v, ignored_cost) = neighbor;
rg.AddEdge(v, u);
}
}
return rg;
}
示例3: Explore
void Explore(const AdjacencyList& graph,
Vertex u,
vector<bool>& visited,
vector<Vertex>& sorted) {
visited[u] = true;
for (const Neighbor& neighbor : graph.GetNeighbors(u)) {
Vertex v;
double ignored_cost;
std::tie(v, ignored_cost) = neighbor;
if (!visited[v]) {
Explore(graph, v, visited, sorted);
}
}
// When DFS is finished on this node, add itself to *sorted* list.
sorted.push_back(u);
}