p273.cpp

来自「数据结构各种算法的实现」· C++ 代码 · 共 17 行

CPP
17
字号
#include "iostream.h"
#include "p271.cpp"
template <class NameType, class DistType>
void Graph<NameType, DistType>::Components ( ) {        //确定图的连通分量
   int *visited = new int[NumVertices];			// visited记录顶点是否访问过
   for ( int i=0; i<NumVertices; i++ ) visited[i] = 0;	//初始化, 表示所有顶点未访问过
   for ( i=0; i<NumVertices; i++ )			//顺序扫描所有顶点
	 if ( !visited[i] ) {				//若没有访问过, 则访问这个连通分量
	   DFS ( i, visited );				//从顶点i开始访问
	   OutputNewComponent ( );			//输出这个连通分量
	 }
   delete [ ] visited;
}
void OutputNewComponent()
{
  cout<<endl<<"The nodes above is of a part."<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?