汉诺塔c++程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Hanoi(platesCount - 1, source, intermediate, destination); Hanoi(1, source, destination, intermediate); Hanoi(platesCount - 1, intermediate, destination, source); return ; } }
} // Draws stands and plates// then do Invalidate// this operation is required// in each stepvoid HanoiDrawer::ReDraw() {
DrawStands();
DrawPlates();
Invalidate(); } // The internal function that is responsible// about solve the problem.// platesCount : how many plates// source : the index of the source// destination : the index of the destination// intermediate : the index of the intermediatevoid HanoiDrawer::Hanoi(int platesCount, int source, int destination, int intermediate) {
if (platesCount == 1) {
listSavedState.push_back(platesCount); listSavedState.push_back(source); listSavedState.push_back(destination); listSavedState.push_back(intermediate); return ; } else {
Hanoi(platesCount -1, from, by, dest); Hanoi(1, from, dest, by); Hanoi(platesCount -1, by, dest, from); } } // Advance one step to solve Hanoivoid HanoiDrawer::SolveNextStep() { int platesCount , source , destination , intermediate;
if (listSavedState.size()==0) {
this->Hanoi(this->iPlatesCount, HanoiDrawer::SOURCE , HanoiDrawer::DESTINATION,
HanoiDrawer::INTERMEDIATE); }
if(listSavedState.size() % 4 != 0 ) {
void Hanoi(int platesCount, int from, int dest, int by) {
if (platesCount==1) {
printf( "Move the plate from %d to %d through %d" , from, dest, by);
} else {
SetDlgItemText(this->hWnd, this->toContainerResourceId , PlaceIntToString(destination).c_str() );
SetDlgItemText(this->hWnd, this->throughContainerResourceId , PlaceIntToString(intermediate).c_str() );
intermediate = listSavedState.front(); listSavedState.pop_front();
ห้องสมุดไป่ตู้
MovePlateFromTo(source, destination);
this - > iMovesCount++;
if(iMovesCount == this->GetTotalMovesCount()) {
this->solved = true; }
SetDlgItemInt(this->hWnd, this->countContainerResourceId, GetMovesCount(), FALSE);
SetDlgItemText(this->hWnd, this->fromContainerResourceId, PlaceIntToString(source).c_str() );
return ; }
platesCount = listSavedState.front(); listSavedState.pop_front();
source = listSavedState.front(); listSavedState.pop_front();
destination = listSavedState.front(); listSavedState.pop_front();
相关文档
最新文档