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


C++ PGraph::DFS方法代码示例

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


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

示例1: main

int main()
{
	//Number of levels 
	
	int emptyStart = 0;
	int final_level = 0;
	int final_number = 0;
	int depth = 1;
	//string config =		  "1110111111111111111111111111111111111111111111111111111";
	//string final_config = "0000000000100000000000000000000000000000000000000000000";
	int n;// = 8;
	string config;// =		  "01111111111111111111111111111111111111111111111111111111111111111";
	string final_config;// = "100000000000000000000000000000000000000000000000000000000000000000";

	cout<<"Please enter the number of level's you would like in this game: ";
	cin>>n;
	cout<<endl<<"Please enter the initial state which is a series of "<<(float)(n*(n+1)/2)<<" 0's and 1's where 1 reprents a peg and 0 represents an empty space."<<endl;
	cin>>config;
	cout<<endl<<"Please enter the final state which is a series of "<<(float)(n*(n+1)/2)<<" 0's and 1's where 1 reprents a peg and 0 represents an empty space."<<endl;
	cin>>final_config;
	cout<<endl<<endl;
	PegTable *found;

	PegTable *table = new PegTable(n,config);
	PGraph graph;
	stack<PegTable*> stac;
	const clock_t begin_time = clock();
	found = graph.DFS(table,final_config);
	cout<<endl<<float((clock() - begin_time))/1000<<" seconds"<<endl<<endl;
	if(found == 0)
	{
		cout<<"The solution state for this configuration does not exist"<<endl;
		return 0;
	}

//	sf::Clock Clock;
//

	while(found != 0)
	{
		stac.push(found);
		found = found->parent;
	}


	
	while(!stac.empty())
	{
		found = stac.top();
		stac.pop();
		found->Print();
	}

	return 0;
}
开发者ID:kyles0623,项目名称:pegSolitaire,代码行数:55,代码来源:PegSolution.cpp


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