用向量来存储一条邻接链表,存储可连通值。实现了判断是否连通,添加边,添加顶点的功能。
UnDirectGraph.h
#pragma once
include “stdafx.h”
include
using namespace std;
class UnDirectGraph
{
private:
int vCount;
vector *adj;
public:
int GetVCount();
UnDirectGraph(int vCount);
void AddEdge(int v,int w);
vector &Vadj(int v);
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[vCount];
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& UnDirectGraph::Vadj(int v)
{
return adj[v];
}
bool UnDirectGraph::IsConnected(int v,int w)
{
for (vector::iterator iter=adj[v].begin();iter!=adj[v].end();iter++)
{
if (*iter==w)
{
return true;
}
}
return false;
}
int UnDirectGraph::GetVCount()
{
return vCount;
}
代码还算清晰,就不解释了,相信学习C++的同学都看得懂。
tplink路由器默认密码是多少(tplink路由器默认密码详解)
tplink路由器默认密码怎么查看(tplink路由器默认密码查看方法)
tplink无线路由器密码怎么重置(tplink无线路由器密码重置方法)
手机如何设置tplink无线路由器密码和密码共享功能(手机设置tplink无线路由器密码和密码共享功能方法)
tplink无线路由器密码忘记了怎么办(tplink无线路由器密码忘记了解决方案)
tplogin路由器可以无线桥接么(TPLink路由器是否支持无线桥接功能)