用向量来存储一条邻接链表,存储可连通值。实现了判断是否连通,添加边,添加顶点的功能。
UnDirectGraph.h
#pragma once
include “stdafx.h”
include
using namespace std;
class UnDirectGraph
{
private:
int vCount;
vector
public:
int GetVCount();
UnDirectGraph(int vCount);
void AddEdge(int v,int w);
vector
bool IsConnected(int v,int w);
};
UnDirectGraph.cpp
#pragma once
include “stdafx.h”
include “UnDirectGraph.h”
using namespace std;
UnDirectGraph::UnDirectGraph(int _vCount)
{
this->vCount=_vCount;
adj=new vector
for (int i=0;i<vCount;i++)
{
adj[i].clear();
}
}
void UnDirectGraph::AddEdge(int v,int w)
{
adj[v].push_back(w);
adj[w].push_back(v);
}
vector
{
return adj[v];
}
bool UnDirectGraph::IsConnected(int v,int w)
{
for (vector
{
if (*iter==w)
{
return true;
}
}
return false;
}
int UnDirectGraph::GetVCount()
{
return vCount;
}
代码还算清晰,就不解释了,相信学习C++的同学都看得懂。
爱发电网页版登录地址直达-爱发电官网登录入口
查理兹·塞隆评价提莫西·查拉梅 《DuneCrawl》主演
zlibrary最新网址2024_亲测能用的官方入口搜书一键直达 - zlibrary下载安装教程_稳定访问的电子书资源免费获取
迅雷app磁力链是什么-怎么用-迅雷磁力链前缀-格式是什么
Monte Cook 讲述 Jewel in the Sky 超大型地下城怎么彻底变革地下城设计
iphone17pro手机怎么样