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


C++ Graph::DeleteVertex方法代码示例

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


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

示例1: main

int main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	Graph<string, string> g;

	g.InsertVertex("Anchorage");
	g.InsertVertex("Eagle River");
	g.InsertVertex("Old Glenn - AK HWY 1 - AK HWY 3 JCT");
	g.InsertVertex("Wasilla");
	g.InsertVertex("Palmer");
	g.InsertVertex("Talkeetna");
	g.InsertVertex("Fairbanks");

	g.InsertEdge("Anchorage", "Eagle River", "Old Glenn Hwy", 16);
	g.InsertEdge("Eagle River", "Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Old Glenn", 19);
	g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Palmer", "HWY 1", 6);
	g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Wasilla", "HWY 3", 8);
	g.InsertEdge("Wasilla", "Talkeetna", "HWY 3", 70);
	g.InsertEdge("Talkeetna", "Fairbanks", "HWY 3", 300);

	/*try 
	{
		g.InsertEdge("Anchorage", "Eagle River", "Old Glenn Hwy", 16);
	}
	catch (Exception e)
	{
		cout << e << endl;
	}*/

	

	/*Graph<string, string> copy(g);
	Graph<string, string> equal;
	equal = g;*/

	cout << "Depth:" << endl;
	g.DepthFirst(&Print);

	cout << "\nBreadth:" << endl;
	g.BreadthFirst(&Print);

	g.DeleteVertex("Fairbanks");

	try {
		cout << "Invalid Delete" << endl;
		g.DeleteVertex("Fairbanks");
	}
	catch (Exception e) {
		cout << e << endl;
	}

	cout << "\nBreadth after Delete Vertex Fairbanks:" << endl;
	g.BreadthFirst(&Print);

	g.DeleteEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Wasilla", "HWY 3", 8);
	cout << "\nDepth after Delete Edge:" << endl;
	g.DepthFirst(&Print);
	return 0;
}
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:59,代码来源:Main.cpp

示例2: main

int main()
{
	Graph head;
	std::cout << &head << std::endl;
	std::cout << head.InsertVertex('a')->GetName() << std::endl;
	std::cout << head.InsertVertex('b')->GetName() << std::endl;
	std::cout << head.InsertVertex('c')->GetName() << std::endl;
	std::cout << head.InsertVertex('d')->GetName() << std::endl;
	std::cout << head.GetFirstVertex()->GetName() << std::endl;
	std::cout << head.InsertEdge('a', 'b')->GetName() << std::endl;
	std::cout << head.InsertEdge('a', 'c')->GetName() << std::endl;
	std::cout << head.InsertEdge('a', 'd')->GetName() << std::endl;
	std::cout << head.InsertEdge('b', 'a')->GetName() << std::endl;
	std::cout << head.DeleteEdge('b', 'a') << std::endl;
	std::cout << head.DeleteEdge('a', 'b') << std::endl;
	std::cout << head.DeleteEdge('a', 'c') << std::endl;
	std::cout << head.DeleteEdge('a', 'd') << std::endl;
	std::cout << head.DeleteVertex('b') << std::endl;
	std::cout << head.DeleteVertex('c') << std::endl;
	std::cout << head.DeleteVertex('d') << std::endl;

	return 0;
}
开发者ID:NAIVEddd,项目名称:data-structure-and-algorithms,代码行数:23,代码来源:main.cpp


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