图的层次遍历

图的层次遍历分层

#include
#include
using namespace std;
const int v=6;
int map[][v]={   //邻接矩阵表示图 
{0,1,1,0,0,0},
{0,0,0,1,1,0},
{0,0,0,0,0,1},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
};
int visit[v]={0};   //访问标记数组 


int main(){
	
	int boot=0;
	int last=boot;   //指向每一层最后一个节点 
	int tail;
	queueq;
	q.push(boot);
	int temp;
	while(!q.empty()){
		temp=q.front();
		visit[temp]=1;
		cout<

你可能感兴趣的:(图论算法)