⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hanoi.cpp

📁 a book on how to use c++ effectively
💻 CPP
字号:
// Hanoi.cpp: implementation of the CHanoi class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "new汉诺塔.h"
#include "Hanoi.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CHanoi::CHanoi(int a)
{
    totalDisks=a;
	count=0;
}

CHanoi::CHanoi()
{
    count=0;
	i=0;
}


CHanoi::~CHanoi()
{

}


void CHanoi::setTotalDiks(int total)
{
	totalDisks=total;
}


int  CHanoi::getTotalDisks()
{
	return totalDisks;
}

void CHanoi::slove()
{
//	m_list1.InsertItem(0,"fsg");
	movetower(totalDisks,1,3,2);
}

void CHanoi::movetower(int numDisk,int start,int end,int temp)
{
	if(numDisk==1)
		moveOneDisk( start, end);
	else
	{
		movetower(numDisk-1,start,temp,end);
		moveOneDisk(start,end);
		movetower(numDisk-1,temp,end,start);
	}
}

void CHanoi::moveOneDisk(int start,int end)
{
//	cout<<"将一个盘从"<<start<<"搬到"<<end<<endl;
//	CHanoi  hanoi(4);
  //   m_list.InsertItem("dsfs");
//	CWnd::GetDlgItem(IDC_LIST1)->InsertItem(0,"jkl");
//	pParent->GetDlgItem(IDC_LIST1)->InsertItem();
//	m_list.InsertItem(0,"fsg");
		count++;
  //  static CString str[]
	//	str=new CString[count+1];
//	static int i=0;
	s.Format("%d",start);
	str[i]="将一个盘从"+s;
	s.Format("%d",end);
	str[i]=str[i]+"搬到"+s;
	++i;


      

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -