本文整理汇总了C++中Digraph::reverse方法的典型用法代码示例。如果您正苦于以下问题:C++ Digraph::reverse方法的具体用法?C++ Digraph::reverse怎么用?C++ Digraph::reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Digraph
的用法示例。
在下文中一共展示了Digraph::reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: order
/* @brief construct a SCC with a graph and compute
* strongly connected component
* @param dg Digraph
*/
SCC::SCC(const Digraph &dg){
//initialize private menber
marked = vector<bool>(dg.V(),false);
__id = vector<int>(dg.V());
__count = 0;
for(int i=0; i<dg.V(); ++i){
__id[i] = i;
}
//dg's reverse graph
const Digraph rdg = dg.reverse();
//rdg's order
DFSOrder order(rdg);
//reverse order of dg's reverse graph
deque<int> reverseOrder = order.reverseOrder();
//depth first searh in reverseOrder
__count = 0;
int num = reverseOrder.size();
for(int i=0; i<num; ++i){
int v = reverseOrder[i];
if( !marked[v] ){
dfs(dg,v);
//search one strongly connected component
++__count;
}
}
}
示例2: DepthFirstOrder
KosarajuSCC::KosarajuSCC(Digraph& dg) {
marked = new bool[dg.n()];
for (int i = 0; i < dg.n(); i++)
marked[i] = false;
id = new int[dg.n()];
count = 0;
Digraph* dgR = dg.reverse();
DepthFirstOrder* dforder = new DepthFirstOrder(*dgR);
stack<int>& reverseOrder = dforder->reversePostOrder();
delete dgR;
while (!reverseOrder.empty()) {
int v = reverseOrder.top();
reverseOrder.pop();
if (!marked[v]) {
dfs(dg, v);
count++;
}
}
delete dforder;
}