| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2454 人关注过本帖
标题:迷宫问题的算法——完备
只看楼主 加入收藏
jasen325
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-19
收藏
 问题点数:0 回复次数:7 
迷宫问题的算法——完备
这学期开始学数据结构,总觉提书中提的算法还完备,要么有时是死循环,要么就是只满足只有单条路径,好像都不够完善。谁有好的算法?
搜索更多相关主题的帖子: 迷宫 算法 
2006-09-19 22:58
胖胖
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-12-25
收藏
得分:0 

怎么没有源程序参考一下啊,

2006-12-25 10:11
诱惑di街
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-3-22
收藏
得分:0 

新手
2007-03-22 19:21
诱惑di街
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-3-22
收藏
得分:0 
怎么还没有啊!

新手
2007-03-27 15:49
cedricporter
Rank: 1
等 级:新手上路
帖 子:49
专家分:3
注 册:2007-2-6
收藏
得分:0 

[CODE]

#ifndef SStack_H
#define SStack_H
// 版权没有。。。。欢迎盗版.... -_-ii
// Made By [Stupid.ET] Cedric Porter
#include <iostream>
#include <cassert>
using namespace std;

template<class T>
class Stack;

template<class T>
class Node
{
T data;
Node *next;
public:
Node(T d, Node<T>* n) { data = d; next = n;}
friend class Stack<T>;
};

template<class T>
class Stack
{
Node<T> *head, *iter;
unsigned long sz;
public:
Stack() {head = iter = NULL; sz = 0;}
~Stack() {empty();}
void empty();
void push(T);
void pop();
T top();
unsigned long size();
};

template<class T>
void Stack<T>::empty()
{
while (head != NULL)
{
iter = head;
head = head->next;
delete head;
}
sz = 0;
}
template<class T>
void Stack<T>::push(T d)
{
if (head == NULL)
head = new Node<T>(d, NULL);
else
head = new Node<T>(d, head);
sz++;
}

template<class T>
void Stack<T>::pop()
{
assert(head != NULL);
sz--;
if (head->next == NULL)
{
delete head;
head = NULL;
return;
}

iter = head;
head = head->next;
delete iter;
}

template<class T>
T Stack<T>::top()
{
assert(head != NULL);
return head->data;
}

template<class T>
unsigned long Stack<T>::size()
{
return sz;
}
#endif



[/CODE]


清脆的口琴聲﹏悠揚的旋律﹏然而︵每個音符︵?°都充滿了悲傷︵?°~↘
2007-04-01 09:17
cedricporter
Rank: 1
等 级:新手上路
帖 子:49
专家分:3
注 册:2007-2-6
收藏
得分:0 

[CODE]
#include "SStack.h"
#include <iostream>
#include <fstream>
// The way to output
#define output_1
// Option
using namespace std;

struct Position
{
int x,y;
};

const int x = 6, y = 6;

int main()
{
int a[x][y];
ifstream inf("m.txt");
for (int i = 0; i <= x; i++)
for (int j = 0; j <= y; j++)
inf >> a[i][j];

Stack<Position> s;
//stack< Position , list<Position> > s;
bool go = true;
Position p;
p.x = p.y = 0;
s.push(p);
while (go)
{
if (s.top().x > x || s.top().y > y)
{
s.pop();
s.pop();
}
go = false;
if (a[s.top().x+1][s.top().y] == 0)
{
p.x = s.top().x + 1;
p.y = s.top().y;
s.push(p);
a[p.x][p.y] = 1;
go = true;
}
else if (a[s.top().x][s.top().y+1] == 0)
{
p.x = s.top().x;
p.y = s.top().y + 1;
s.push(p);
a[p.x][p.y] = 1;
go = true;
}
else if (a[s.top().x-1][s.top().y] == 0)
{
p.x = s.top().x - 1;
p.y = s.top().y;
s.push(p);
a[p.x][p.y] = 1;
go = true;
}
else if (a[s.top().x][s.top().y-1] == 0)
{
p.x = s.top().x;
p.y = s.top().y - 1;
s.push(p);
a[p.x][p.y] = 1;
go = true;
}
else
{
s.pop();
go = true;
}

if (s.top().x == x && s.top().y == y)
{
break;
}
}

//*
// Output
#ifdef output_1
Stack<Position> t;
while (s.size() != 0)
{
p = s.top();
p.x++;
p.y++;
t.push(p);
s.pop();
}
while (t.size() != 0)
{
cout << t.top().x << ' ' << t.top().y << endl;
t.pop();
}


#else
int ii, jj;
for (ii = 0; ii < x; ii++)
for (jj = 0; jj < y; jj++)
a[ii][jj] = 1;

while (s.size() != 0)
{
a[s.top().x][s.top().y] = 31;
s.pop();
}

for (ii = 0; ii < x; ii++)
{
for (jj = 0; jj < y; jj++)
cout << char(a[ii][jj]+1) << ' ';
cout << endl;
}
#endif
//*/
system("pause");

return 0;
}

[/CODE]


清脆的口琴聲﹏悠揚的旋律﹏然而︵每個音符︵?°都充滿了悲傷︵?°~↘
2007-04-01 09:18
wu0720
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-8
收藏
得分:0 
2007-04-08 22:22
快速回复:迷宫问题的算法——完备
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014570 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved