本文整理汇总了C++中graph::getEdge方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::getEdge方法的具体用法?C++ graph::getEdge怎么用?C++ graph::getEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::getEdge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findMSF
void findMSF(graph &g, graph &sf, int start)
// finds a minimum spanning tree in graph 'g'
{
priority_queue<edge, vector<edge>, CompareEdge> pq;
vector<int> lst = getNeighbors(start, g);
// build our priority queue
for (int i = 0; i < lst.size(); i++)
{
pq.push(g.getEdge(start, lst[i]));
g.mark(start, lst[i]);
}
// visit the start node
g.visit(start);
int src, dst, w;
edge top;
while (!pq.empty())
{
top = pq.top();
pq.pop();
src = top.getSource();
dst = top.getDest();
w = top.getWeight();
// add edges
if (!sf.isEdge(src, dst))
{
sf.addEdge(src, dst, w);
sf.addEdge(dst, src, w);
// delete edges if we make a cycle
if (isCyclic(sf))
{
sf.removeEdge(src, dst);
sf.removeEdge(dst, src);
}
else
{
g.visit(src);
lst = getNeighbors(dst, g);
for (int i = 0; i < lst.size(); i++)
{
if (!g.isMarked(dst, lst[i]))
{
pq.push(g.getEdge(dst, lst[i]));
g.mark(dst, lst[i]);
}
} // for
} // else
} // if
} // while
} // findMSF
示例2: nonRecursiveDFS
vector<stack<int> > nonRecursiveDFS(int startId, int dstId, graph &g )
// implement a version of Depth First Search that uses a stack data structure
// and does not use recursion returns all paths
{
vector< stack<int> > paths;
stack<int> st;
stack<edge> edges;
st.push(startId);
stack<int> path;
while (!st.empty())
{
int top = st.top();
//check if before we had gone into a sink and remove from path
while (!edges.empty() && path.top() != edges.top().getSource())
{
path.pop();
}
path.push(top);
if (!edges.empty())
{
edges.pop();
}
st.pop();
g.visit(top);
if (top == dstId)
{
paths.push_back(path);
}
vector<int> lst = getNeighbors(top, g);
for (int i = 0; i < lst.size(); i++)
{
if (!g.isVisited(lst[i]))
{
st.push(lst[i]);
edges.push(g.getEdge(top, lst[i]));
}
}
}
return paths;
}