管理 给我的留言
- myjeya | 2011-08-29 16:36:22
- 能加我嗎50630786,我是工作兩年的測試員
- summertears | 2011-05-19 22:51:24
- 学习来啦 群主
- 天上的星星 | 2011-05-18 17:25:45
- 悄悄话,只给空间主人查看...
- jijy2010 | 2010-12-20 15:12:40
- 嗨,,,,,
- 张艺文 | 2010-12-11 19:59:00
-
#include<iostream.h>
struct ArcNode//定义边表结点
{ int adjvex;//邻接点域
ArcNode *next;
};
template <class T>
struct VertexNode //定义顶点表结点
{
T vertex;//
ArcNode *firstedge;
};
const int MaxSize=10; //图的最大顶点数
int visited [MaxSize];
template <class T>
class ALGraph
{
public:
ALGraph(T a[ ], int n, int e); //n是顶点数,e是边数
~ALGraph(){}
void DFSTraverse(int v);
void BFSTraverse(int v);
private:
VertexNode<T> adjlist[MaxSize]; //??????????
int vertexNum, arcNum;
};
template <class T>
ALGraph<T>::ALGraph(T a[ ], int n, int e)
{
vertexNum=n; arcNum=e;
int i,j,k;
ArcNode *s;
ArcNode *p;
for (i=0; i<vertexNum; i++)
//输入顶点信息,初始化边表
{
adjlist[i].vertex=a[i];
adjlist[i].firstedge=NULL; // 以上两句是什么意思????一个链表还是 vertexNum个链表??
}
for (k=0; k<arcNum; k++)
//输入边的信息存储在边表中
{
cin>>i>>j;
s=new ArcNode;
s->adjvex=j;
s->next=adjlist[i].firstedge;
adjlist[i].firstedge=s;
p=new ArcNode;
p->adjvex=i;
p->next=adjlist[i].firstedge;
adjlist[i].firstedge=p;
}
}
template <class T>
void ALGraph<T>::DFSTraverse(int v)
{
ArcNode *p;
int j;
cout<<adjlist[v].vertex; visited[v]=1;
p=adjlist[v].firstedge;
while (p!=NULL)
{
j=p->adjvex;
if (visited[j]==0) DFSTraverse(j);
p=p->next;
}
}
template <class T>
void ALGraph<T>::BFSTraverse(int v)
{
int Q[MaxSize],front,rear,j;
ArcNode *p;
front=rear=-1; //假设采用顺序队列且不会发生溢出
front=rear=-1;
cout<<adjlist[v].vertex; visited[v]=1; Q[++rear]=v;
while (front!=rear)
{
v=Q[++front]; p=adjlist[v].firstedge;
while (p!=NULL)
{
j= p->adjvex;
if (visited[j]==0) {
cout<<adjlist[j].vertex; visited[j]=1; Q[++rear]=j;
}
p=p->next;
}
if(visited[v+1]==0) v=v+1;
}
}
void main()
{
int a[5]={0,1,2,3,4};
ALGraph<int> graph(a,5,4);
graph.BFSTraverse(0);
}2010-12-15 09:20:52
不明白你的留言
- 羽藤 | 2010-12-07 13:57:04
-
您好。我对测试一窍不通。希望你能指导一下(*^__^*) ……
O(∩_∩)O谢谢2010-12-15 09:20:15
加入我的群吧,我们共同学习吧
- 江潭素月 | 2010-11-24 11:25:47
-
你好,能告诉我你的qq吗,想请教你关于jprofiler的问题,谢谢了
2010-12-15 09:19:32
我的QQ63181631
- kxg650341 | 2010-07-01 10:53:38
-
我也是在杭州做测试哎。。。。。。qtp我们都不太用的。。。
2010-07-01 12:46:05
我也是,真正认真研究也就6月份的事,一起学习吧
- Joyeer | 2010-05-04 14:13:52
- 好地方~
标题搜索
我的存档
数据统计
- 访问量: 462815
- 日志数: 125
- 建立时间: 2007-05-28
- 更新时间: 2016-09-27