【数据结构作业五】以邻接表作存储结构,广度遍历图的优先搜索序列

#include 
#define MVNum 100
#define MAXQSIZE 100
using namespace std;
typedef char ElemType;
typedef int QElemType;
typedef struct {
	QElemType *base;
	int front,rear;
}SqQueue;
typedef struct ArcNode
{
	int adjvex;
	struct ArcNode *nextarc;
}ArcNode;
typedef struct 
{
	ElemType data;
	ArcNode *firstarc;
}VerNode;
typedef  struct 
{  VerNode  vertices[MVNum];
    int   vernum, arcnum;
}ALGraph;
int Locate(ALGraph G, ElemType v)
{
	for(int i=0;i>G.vernum >>G.arcnum;
    for (i=0;i>G. vertices[i].data;  //读入顶点
          G. vertices[i]. firstarc=NULL; 
      }    
    for (k=1;k<=G.arcnum;k++)
      {   
          cout<<"请输入一条边:";
	      cin>>v1>>v2;  //读入一条弧
          i=Locate(G,v1);  j=Locate(G,v2);  //查找顶点在顶点表中的位置
          p=new ArcNode;  p->adjvex=j; 
          p->nextarc= G. vertices[i]. firstarc;
          G. vertices[i]. firstarc=p;
      }
}
int FirstAdjVex(ALGraph G,ElemType v)
{

	ArcNode *p=G. vertices[v]. firstarc;
	if(p){
		return p->adjvex;
	}
	else{
		return -1;
	}
}
int NextAdjVex(ALGraph G,ElemType v,ElemType w)
{
 
	ArcNode *p=G. vertices[v]. firstarc;
	while(p){
		if(p->adjvex==w) break;
		p=p->nextarc;
	}
	if(!p||!p->nextarc){
		return -1;
	}
	else{
		return (p->nextarc)->adjvex;
	}
}
bool  visited[MVNum]; 
void BFS(ALGraph G,int v)
{
	SqQueue Q;
	QElemType u;
	int w;
	InitQueue(Q);
	cout<=0;w=NextAdjVex(G,u,w))
		if(!visited[w])
		{
			cout<

你可能感兴趣的:(数据结构,大学)