本文整理汇总了C++中Digraph::TopologicalSort方法的典型用法代码示例。如果您正苦于以下问题:C++ Digraph::TopologicalSort方法的具体用法?C++ Digraph::TopologicalSort怎么用?C++ Digraph::TopologicalSort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Digraph
的用法示例。
在下文中一共展示了Digraph::TopologicalSort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
cout << "\tAcyclic Check Finished: expect true: " << boolToString(digraph->AcyclicCheck()) << endl << endl;
cout << "\nTest an even more complex graph... Reconfigure list to run more checks: \n";
digraph->AddHeader("task name-10");
digraph->RemoveEdge(4, 1);
digraph->RemoveEdge(2, 4);
digraph->RemoveEdge(2, 5);
digraph->RemoveEdge(5, 3);
digraph->RemoveEdge(3, 6);
digraph->RemoveEdge(6, 4);
digraph->RemoveEdge(6, 1);
digraph->AddEdge(1, 2);
digraph->AddEdge(1, 7);
digraph->AddEdge(1, 6);
digraph->AddEdge(1, 4);
digraph->AddEdge(2, 3);
digraph->AddEdge(3, 5);
digraph->AddEdge(4, 5);
digraph->AddEdge(4, 6);
digraph->AddEdge(6, 7);
digraph->AddEdge(7, 5);
cout << "result print: \n";
digraph->PrintAdjacencyList();
cout << "Running Acyclic Check...\n";
cout << "\tAcyclic Check Finished: expect true: " << boolToString(digraph->AcyclicCheck()) << endl << endl;
cout << "\nTest complex graph with many cycles: \n";
digraph->AddEdge(7, 4);
digraph->AddEdge(2, 4);
digraph->AddEdge(5, 1);
cout << "result print: \n";
digraph->PrintAdjacencyList();
cout << "Running Acyclic Check...\n";
cout << "\tAcyclic Check Finished: expect false: " << boolToString(digraph->AcyclicCheck()) << endl;
cout << endl << endl;
delete digraph; // Clean up digraph to make predictable case.
digraph = new Digraph();
cout << "\n==========> TEST TOPOLOGICAL SORT\n" << endl;
digraph->AddHeader("task name-1");
digraph->AddHeader("task name-2");
digraph->AddHeader("task name-3");
digraph->AddHeader("task name-4");
digraph->AddHeader("task name-5");
// 3 ^ One Direction, up
cout << "\nAdd Edges (1,2), (2,4), (1,4), (4,5), (4,3):\n"; // ^ v One Direction, down
digraph->AddEdge(1,2); // 2 > 4 > One Direction, right
digraph->AddEdge(2,4); // ^ / v / One Direction, botLeft -> topRight
digraph->AddEdge(1,4); // 1 5
digraph->AddEdge(4,5);
digraph->AddEdge(4,3);
digraph->PrintAdjacencyList();
cout << "Expected: 1->2->4->3->5\n";
cout << " OR: 1->2->4->5->3\n";
digraph->TopologicalSort();
cout << "\nAdd Header (no edges)\nExpected: new task (6) will appear. Order doesn't matter.\n";
digraph->AddHeader("task name-6");
digraph->TopologicalSort();
cout << "\nAdd Edge (5,6)\nExpected: task 6 will schedule ONLY after task 5.\n";
digraph->AddEdge(5,6);
digraph->TopologicalSort();
cout << "\nAdd Edge (6,3)\nExpected: task 6 will schedule after task 3, which is after task 5. (5->3->6)\n";
digraph->AddEdge(3,6);
digraph->TopologicalSort();
cout << "\nRemove edge (4,5)\nExpected: task 5 and successors may appear anywhere in the list (in correct order)\n";
digraph->RemoveEdge(4,5);
digraph->TopologicalSort();
cout << "\nTest Cyclic\nExpected: Cyclic check error.\n";
digraph->AddEdge(4,1);
digraph->TopologicalSort();
digraph->RemoveEdge(4,1);
cout << "\nRemove 'task name-4'\nExpected: all edges to/from 'task name-4' will be removed. Successor task strings may occur before predecessor strings.\n";
digraph->RemoveHeader_(4);
digraph->TopologicalSort();
cout << "\n=========> Finish TopologicalSort"<<endl;
// clean up created object(s)
cout << endl << endl;
delete digraph;
cout << "------------------------END TEST OF DIGRAPH CLASS------------------------" << endl;
cout << endl;
return 0;
}