資源簡介
數據結構Prim最小生成樹
代碼片段和文件信息
#include
#include?“graph.h“
#include?/*?INT_MAX等?*/
using?namespace?std;
template
inline?MGraph::MGraph(T?a[]?int?n?int?e)
{
????vertexNum?=?n;
????arcNum?=?e;
????for?(int?i?=?0;?i?????????vertex[i]?=?a[i];
????for?(int?i?=?0;?i?????????for?(int?j?=?0;?j?????????????arc[i][j]?=?INT_MAX;
????for?(int?k?=?0;?k?????{
????????int?i?jw;
????????cout<<“please?input?vertex?Num(ij)?and?weight:“< ????????std::cin?>>?i?>>?j>>w;????????//?輸入邊依附的頂點的編號
????????arc[i][j]?=?w;????????????//?置有邊標記
????????arc[j][i]?=?w;
????}
}
template
inline?void?MGraph::DFSTraaverse(int?v)
{????
????cout?<????visited[v]?=?1;
????for?(int?j?=?0;?j?????{
????????if?(arc[v][j]?==?1?&&?visited[j]?==?0)
????????????DFSTraaverse(j);
????}
}
template
inline?void?MGraph::BFSTraverse(int?v)
{
評論
共有 條評論