资源简介
网上大部分解决8数码问题都只采用宽度优先算法。我在宽度优先的基础上,设计出深度优先算法。并制作出界面,方便输入、输出。希望能对学习相关内容的同志有所帮助
代码片段和文件信息
#include “StdAfx.h“
#include “BfsDfs.h“
CBfsDfs::CBfsDfs(void)
{
}
CBfsDfs::~CBfsDfs(void)
{
delete beg; //解决内存泄露的问题!
while(!m_Queue.empty())
{
map *inter=m_Queue.front();
m_Queue.pop();
delete inter;
}
}
CBfsDfs::CBfsDfs(int *pointint *goal)
{
numStep = 0;
beg = new map;
for (int n=0;n {
beg->dig[n] = *(point+n);
end.dig[n] = *(goal+n);
}
beg->last = NULL;
beg->lockDir = None;
beg->layer = 0;
}
bool CBfsDfs::Judge()
{
int a1=numDes(&end);
int a2=numDes(beg);
if(a1!=a2) return 0;
if (CheckRepeat(beg)) return 0;
if (CheckRepeat(&end)) return 0;
return 1;
}
void CBfsDfs::Cal(bool BorD)
{
double startTime=clock(); //设计计时器,计算所用过的时间
if (0 == BorD)
{
T=BNFS(beg&end);
}
else
{
T=DNFS(beg&end);
}
double endTime=clock();
if(T != NULL)
{
map *p=T;
stack
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5127 2010-09-16 15:36 EightPuzzle\EightPuzzle\BfsDfs.cpp
文件 1413 2010-09-16 14:50 EightPuzzle\EightPuzzle\BfsDfs.h
文件 61684 2010-09-16 15:12 EightPuzzle\EightPuzzle\EightPuzzle.aps
文件 1714 2010-09-14 19:04 EightPuzzle\EightPuzzle\EightPuzzle.cpp
文件 471 2010-09-14 19:04 EightPuzzle\EightPuzzle\EightPuzzle.h
文件 14655 2010-09-16 15:12 EightPuzzle\EightPuzzle\EightPuzzle.rc
文件 5635 2010-09-14 19:42 EightPuzzle\EightPuzzle\EightPuzzle.vcproj
文件 1425 2010-09-16 15:36 EightPuzzle\EightPuzzle\EightPuzzle.vcproj.yangtianzhi-PC.yangtianzhi.user
文件 6803 2010-09-16 15:25 EightPuzzle\EightPuzzle\EightPuzzleDlg.cpp
文件 1184 2010-09-16 15:25 EightPuzzle\EightPuzzle\EightPuzzleDlg.h
文件 2835 2010-09-14 19:04 EightPuzzle\EightPuzzle\ReadMe.txt
文件 21630 2005-12-08 14:56 EightPuzzle\EightPuzzle\res\EightPuzzle.ico
文件 367 2010-09-14 19:04 EightPuzzle\EightPuzzle\res\EightPuzzle.rc2
文件 1741 2010-09-16 15:12 EightPuzzle\EightPuzzle\resource.h
文件 142 2010-09-14 19:04 EightPuzzle\EightPuzzle\stdafx.cpp
文件 2489 2010-09-14 19:04 EightPuzzle\EightPuzzle\stdafx.h
文件 898 2010-09-14 19:04 EightPuzzle\EightPuzzle.sln
..A..H. 15360 2010-09-16 15:36 EightPuzzle\EightPuzzle.suo
目录 0 2010-09-14 19:04 EightPuzzle\EightPuzzle\res
目录 0 2010-09-16 15:37 EightPuzzle\EightPuzzle
目录 0 2010-09-16 15:37 EightPuzzle
----------- --------- ---------- ----- ----
145573 21
评论
共有 条评论