当前位置: 首页>>代码示例>>C++>>正文


C++ AdjList::deleteEdge方法代码示例

本文整理汇总了C++中AdjList::deleteEdge方法的典型用法代码示例。如果您正苦于以下问题:C++ AdjList::deleteEdge方法的具体用法?C++ AdjList::deleteEdge怎么用?C++ AdjList::deleteEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AdjList的用法示例。


在下文中一共展示了AdjList::deleteEdge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv) {
    AdjList *al = new AdjList;
    cout << "Adding Vertices 1,2,3,4,5,6\n";
    al->addVertex("1");
    al->addVertex("2");
    al->addVertex("3");
    al->addVertex("4");
    al->addVertex("5");
    al->addVertex("6");
    cout << "\nAdding duplicate vertex:\n";
    al->addVertex("1");
    
    cout << "\nAdding valid edges 1->2,1->3,2->4,2->5,3->2,3->5,5->4,4->6,5->6\n";
    al->addEdge("1","2");
    al->addEdge("1","3");
    al->addEdge("2","4");
    al->addEdge("2","5");
    al->addEdge("3","2");
    al->addEdge("3","5");
    al->addEdge("5","4");
    al->addEdge("4","6");
    al->addEdge("5","6");
    cout << "\nAdding invalid edges:\n";
    al->addEdge("1","A");
    al->addEdge("A","4");
    
    cout << "\nPrinting Graph:\n";
    al->printGraph();
    
    cout << "\nTraversing Graph in BFS from valid source:\n";
    al->traverseBFS("1");
    
    cout << "\nTraversing Graph in BFS from invalid source:\n";
    al->traverseBFS("A");
    
    cout << "\nTraversing Graph in DFS:\n";
    al->traverseDFS();
    
    if(al->isDAG()){
        cout << "Graph is a DAG\n";
    }else{
        cout << "Graph is NOT a DAG\n";
    }
    
    cout << "\nMaking a copy graph\n";
    AdjList *copy = al->copyGraph();
    
    cout << "\nDeleting valid vertex 2 from original\n";
    al->deleteVertex("2");
    
    cout << "\nDeleting invalid vertex from original:\n";
    al->deleteVertex("2");
    
    cout << "\nPrinting Copied Graph:\n";
    copy->printGraph();
    
    cout << "\nPrinting Original Graph:\n";
    al->printGraph();
    
    cout << "\nTraversing Original Graph in BFS from valid source:\n";
    al->traverseBFS("1");
    
    cout << "\nTraversing Original Graph in BFS from invalid source:\n";
    al->traverseBFS("2");
    
    cout << "\nTraversing Original Graph in DFS:\n";
    al->traverseDFS();
    
    cout << "\nDeleting valid edge 4->6 from Original Graph\n";
    al->deleteEdge("4","6");
    
    cout << "\nDeleting invalid edge 4->6 from Original Graph\n";
    al->deleteEdge("4","6");
    cout << "\nDeleting invalid edge 1->2 from Original Graph\n";
    al->deleteEdge("1","2");
    
    cout << "\nPrinting Original Graph:\n";
    al->printGraph();
    
    cout << "\nPrinting Copied Graph:\n";
    copy->printGraph();
    
    cout << "\nTraversing Copied Graph in BFS from valid source:\n";
    copy->traverseBFS("1");
    
    cout << "\nTraversing Copied Graph in DFS:\n";
    copy->traverseDFS();
    
    cout << "\nDeleting Vertices from original graph:\n";
    al->deleteVertices();
    
    cout << "\nAdding Vertices and edges to form cycle to original graph:\n";
    al->addVertex("1");
    al->addVertex("2");
    al->addEdge("1","2");
    al->addEdge("2","1");
    
    cout << "\nPrinting original Graph:\n";
    al->printGraph();
    
//.........这里部分代码省略.........
开发者ID:mirob2005,项目名称:CPP_Data_Structures,代码行数:101,代码来源:main.cpp


注:本文中的AdjList::deleteEdge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。