当前位置: 首页 > news >正文

个人能否做网站超级seo外链

个人能否做网站,超级seo外链,顺企网企业查询,一键发布多个自媒体平台文章目录 图的基本概念邻接矩阵邻接表图的遍历BFSDFS 图的基本概念 图是由顶点集合及顶点间的关系组成的一种数据结构 顶点和边:图中结点称为顶点 权值:边附带的数据信息 路径 : 简单路径 和 回路: 子图:设图G {V, E}和图G1…

文章目录

  • 图的基本概念
  • 邻接矩阵
  • 邻接表
  • 图的遍历
    • BFS
    • DFS

图的基本概念

图是由顶点集合及顶点间的关系组成的一种数据结构
顶点和边:图中结点称为顶点

权值:边附带的数据信息

在这里插入图片描述

在这里插入图片描述
路径 : 在这里插入图片描述

简单路径 和 回路:在这里插入图片描述

子图:设图G = {V, E}和图G1 = {V1,E1},若V1属于V且E1属于E,则称G1是G的子图
在这里插入图片描述

连通图:在无向图中,若从顶点v1到顶点v2有路径,则称顶点v1与顶点v2是连通的。如果图中任意一对顶点都是连通的,则称此图为连通图

生成树:一个连通图的最小连通子图称作该图的生成树。有n个顶点的连通图的生成树有n个顶点和n-1条边

生成树就是用最少的边连通起来

最小生成树:构成生成树这些边加起来权值是最小的。

顶点的度:
**加粗样式**
在这里插入图片描述

邻接矩阵

在这里插入图片描述

#pragma once 
#include<map>
#include<vector>
#include<algorithm>
#include<assert.h>
#include<string>
#include <functional>
#include<iostream>
using namespace std;
//矩阵 
namespace matrix
{//V是顶点 ,W是 weight 权值 template <class V, class W, W MAX_W = INT_MAX, bool Direction = false>  //true是有向图 ,false是无向图class Graph{public://手动添加边Graph(const V* a, size_t n)  //用指针数组 存储顶点{_vertex.reserve(n);//初始化顶点和边for (size_t i = 0; i < n; i++){_vertex.push_back(a[i]);_indexMap[a[i]] = i; //通过顶点找下标}_matrix.resize(n);for (size_t i = 0; i < n; i++){//将邻接矩阵的权值设置为最大值_matrix[i].resize(n, MAX_W);}}size_t  GetVertexIndexMap(const V& v){auto  it = _indexMap.find(v);if (it != _indexMap.end()){return it->second;}else //没有找到 {assert(false);return -1;}}void AddEdge(const V& src, const V& dst, const W& w){int srci = GetVertexIndexMap(src);int dsti = GetVertexIndexMap(dst);_matrix[srci][dsti] = w;//无向图 if (Direction == false){_matrix[srci][dsti] = w;_matrix[dsti][srci] = w;}}void  Print(){//顶点 for (int i = 0; i < _vertex.size(); i++){cout << "[" << i << "]" << "->" << _vertex[i] << endl;}//矩阵 cout << endl;//打印横下标cout << "  ";for (size_t i = 0; i < _vertex.size(); i++){cout << i << " ";}cout << endl;for (int i = 0; i < _matrix.size(); i++){cout << i << " ";//打印竖下标for (int j = 0; j < _matrix[0].size(); j++){if (_matrix[i][j] == MAX_W){cout << "*"<<" ";}else{cout << _matrix[i][j] <<" ";}}cout << endl;}}public:vector<V> _vertex;  //顶点集合 map<V, int>  _indexMap;					//顶点映射下标 vector< vector<W> >	 _matrix;					//邻接矩阵};void TestGraph(){Graph<char, int, INT_MAX, true> g("0123", 4);g.AddEdge('0', '1', 1);g.AddEdge('0', '3', 4);g.AddEdge('1', '3', 2);g.AddEdge('1', '2', 9);g.AddEdge('2', '3', 8);g.AddEdge('2', '1', 5);g.AddEdge('2', '0', 3);g.AddEdge('3', '2', 6);g.Print();}
}

邻接表

邻接表:使用数组表示顶点的集合,使用链表表示边的关系

出边表:存储从各个顶点连接出去的边,出边表中下标为 i的位置存储的是从编号为i的顶点连接出去的边

入边表:存储连接到各个顶点的边,入边表中下标为i的位置存储的是连接到编号为 i的顶点的边
在这里插入图片描述
出边表和入边表的其中每个位置存储的都是一个链表
出边表中下标为i的位置表示从编号为i的顶点连接出去的边
入边表中下标为i 的位置表示连接到编号为i 的顶点的边

在实现邻接表时,一般只需要用一个出边表来存储从各个顶点连接出去的边即可,因为大多数情况下都是需要从一个顶点出发找与其相连的其他顶点,所以一般不需要存储入边表

//邻接表
namespace link_table
{template<class  W>struct Edge{int _dsti;//目标点的下标 W _w;//权值Edge<W> *_next; //用链表表示边的关系Edge(int dsti, const W& w):_dsti(dsti), _w(w), _next(nullptr)  {}};//V是顶点 ,W是 weight 权值 template <class V, class W, bool Direction = false>  //true是有向图 ,false是无向图class Graph{public:typedef Edge<W> Edge;//手动添加边Graph(const V* a, size_t n)  //用指针数组 存储顶点{_vertex.reserve(n);//初始化顶点和边for (size_t i = 0; i < n; i++){_vertex.push_back(a[i]);_indexMap[a[i]] = i; //通过顶点找下标}_table.resize(n, nullptr);}size_t  GetVertexIndexMap(const V& v){auto  it = _indexMap.find(v);if (it != _indexMap.end()){return it->second;}else //没有找到 {assert(false);return -1;}}void AddEdge(const V& src, const V& dst, const W& w){int srci = GetVertexIndexMap(src); int dsti = GetVertexIndexMap(dst);//头插Edge *eg = new Edge(dsti,w);//有向图 //添加从源顶点到目标顶点的边eg->_next = _table[srci];_table[srci] = eg;//无向图 //添加从目标顶点到源顶点的边if (Direction == false){//????Edge* eg = new Edge(srci, w);eg->_next = _table[dsti];_table[dsti] = eg;}}void  Print(){//顶点 for (int i = 0; i < _vertex.size(); i++){cout << "[" << i << "]" << "->" << _vertex[i] << endl;}cout << endl;//遍历顶点for (size_t i = 0; i < _vertex.size(); i++){cout << _vertex[i] << endl;}//遍历邻接表的目标点的下标和权值 for (size_t i = 0; i < _table.size(); i++){cout << _vertex[i] << "[" << i << "]->";Edge * cur = _table[i];while (cur != nullptr){cout << "[" << _vertex[cur->_dsti] << ":" << cur->_dsti << ":" << cur->_w << "]->";cur = cur->_next;}cout << "nullptr" << endl;}}public:vector<V> _vertex;  //顶点集合 map<V, int>  _indexMap;					//顶点映射下标 vector<  Edge*>	 _table;					//邻接表};void TestGraph(){string a[] = { "张三", "李四", "王五", "赵六" };Graph<string, int, true> g1(a, 4);g1.AddEdge("张三", "李四", 100);g1.AddEdge("张三", "王五", 200);g1.AddEdge("王五", "赵六", 30);g1.Print();}
}

图的遍历

BFS

在这里插入图片描述

void BFS(const V& src)  //遍历顶点,通过下标找顶点{size_t srci = GetVertexIndexMap(src);queue<int>  q;vector<bool>  v(_vertex.size(), false);  //防止走重复的路q.push(srci);v[srci] = true;while (!q.empty()){int front = q.front();q.pop();cout << _vertex[front] << endl;// 把front顶点的邻接顶点的下标入队列for (size_t i = 0; i < _vertex.size(); i++){if (_matrix[front][i] != MAX_W && v[i] == false){q.push(i);v[i] = true;}}}}

DFS

在这里插入图片描述

void _DFS(    size_t srci  ,vector<bool> & v){cout << srci << ":" << _vertex[srci] << endl;v[srci] = true;// 找一个srci相邻的没有访问过的点,去往深度遍历for (int i =0 ; i< _vertex.size()  ; i++ ){if (v[i] ==false && _matrix[srci][i] != MAX_W){_DFS(i ,v);}}}void  DFS(const V& src) //遍历顶点,通过下标找顶点{vector<bool>  v(_vertex.size(), false);  //防止走重复的路size_t  srci = GetVertexIndexMap(src);_DFS(srci, v);}

完整测试代码

#pragma once 
#include<map>
#include<vector>
#include<algorithm>
#include<assert.h>
#include<string>
#include <functional>
#include<iostream>
#include<queue>
using namespace std;
//矩阵 
namespace matrix
{//V是顶点 ,W是 weight 权值 //连通的,边的关系就用权值代替,如果两顶点不通,则使用无穷大代替template <class V, class W, W MAX_W = INT_MAX, bool Direction = false>  //true是有向图 ,false是无向图class Graph{public://手动添加边Graph(const V* a, size_t n)  //用指针数组 存储顶点{_vertex.reserve(n);//初始化顶点和边for (size_t i = 0; i < n; i++){_vertex.push_back(a[i]);_indexMap[a[i]] = i; //通过顶点找下标}_matrix.resize(n);for (size_t i = 0; i < n; i++){//将邻接矩阵的权值设置为最大值_matrix[i].resize(n, MAX_W);}}size_t  GetVertexIndexMap(const V& v){auto  it = _indexMap.find(v);if (it != _indexMap.end()){return it->second;}else //没有找到 {assert(false);return -1;}}void AddEdge(const V& src, const V& dst, const W& w){int srci = GetVertexIndexMap(src);int dsti = GetVertexIndexMap(dst);_matrix[srci][dsti] = w;//无向图 if (Direction == false){_matrix[srci][dsti] = w;_matrix[dsti][srci] = w;}}void  Print(){//顶点 for (int i = 0; i < _vertex.size(); i++){cout << "[" << i << "]" << "->" << _vertex[i] << endl;}//矩阵 cout << endl;//打印横下标cout << "  ";for (size_t i = 0; i < _vertex.size(); i++){cout << i << " ";}cout << endl;for (int i = 0; i < _matrix.size(); i++){cout << i << " ";//打印竖下标for (int j = 0; j < _matrix[0].size(); j++){if (_matrix[i][j] == MAX_W){cout << "*"<<" ";}else{cout << _matrix[i][j] <<" ";}}cout << endl;}}void BFS(const V& src)  //遍历顶点,通过下标找顶点{size_t srci = GetVertexIndexMap(src);queue<int>  q;vector<bool>  v(_vertex.size(), false);  //防止走重复的路q.push(srci);v[srci] = true;while (!q.empty()){int front = q.front();q.pop();cout << _vertex[front] << endl;// 把front顶点的邻接顶点的下标入队列for (size_t i = 0; i < _vertex.size(); i++){if (_matrix[front][i] != MAX_W && v[i] == false){q.push(i);v[i] = true;}}}}void _DFS(    size_t srci  ,vector<bool> & v){cout << srci << ":" << _vertex[srci] << endl;v[srci] = true;// 找一个srci相邻的没有访问过的点,去往深度遍历for (int i =0 ; i< _vertex.size()  ; i++ ){if (v[i] ==false && _matrix[srci][i] != MAX_W){_DFS(i ,v);}}}void  DFS(const V& src) //遍历顶点,通过下标找顶点{vector<bool>  v(_vertex.size(), false);  //防止走重复的路size_t  srci = GetVertexIndexMap(src);_DFS(srci, v);}public:vector<V> _vertex;  //顶点集合 map<V, int>  _indexMap;					//顶点映射下标 vector< vector<W> >	 _matrix;					//邻接矩阵};void TestGraph(){Graph<char, int, INT_MAX, true> g("0123", 4);g.AddEdge('0', '1', 1);g.AddEdge('0', '3', 4);g.AddEdge('1', '3', 2);g.AddEdge('1', '2', 9);g.AddEdge('2', '3', 8);g.AddEdge('2', '1', 5);g.AddEdge('2', '0', 3);g.AddEdge('3', '2', 6);g.Print();}void TestBDFS(){string a[] = { "张三", "李四", "王五", "赵六", "周七" };Graph<string, int> g1(a, sizeof(a) / sizeof(string));g1.AddEdge("张三", "李四", 100);g1.AddEdge("张三", "王五", 200);g1.AddEdge("王五", "赵六", 30);g1.AddEdge("王五", "周七", 30);g1.Print();//g1.BFS("张三");g1.DFS("张三");}
}//邻接表
namespace link_table
{template<class  W>struct Edge{int _dsti;//目标点的下标 W _w;//权值Edge<W> *_next; //用链表表示边的关系Edge(int dsti, const W& w):_dsti(dsti), _w(w), _next(nullptr)  {}};//V是顶点 ,W是 weight 权值 template <class V, class W, bool Direction = false>  //true是有向图 ,false是无向图class Graph{public:typedef Edge<W> Edge;//手动添加边Graph(const V* a, size_t n)  //用指针数组 存储顶点{_vertex.reserve(n);//初始化顶点和边for (size_t i = 0; i < n; i++){_vertex.push_back(a[i]);_indexMap[a[i]] = i; //通过顶点找下标}_table.resize(n, nullptr);}size_t  GetVertexIndexMap(const V& v){auto  it = _indexMap.find(v);if (it != _indexMap.end()){return it->second;}else //没有找到 {assert(false);return -1;}}void AddEdge(const V& src, const V& dst, const W& w){int srci = GetVertexIndexMap(src); int dsti = GetVertexIndexMap(dst);//头插Edge *eg = new Edge(dsti,w);//有向图 //添加从源顶点到目标顶点的边eg->_next = _table[srci];_table[srci] = eg;//无向图 //添加从目标顶点到源顶点的边if (Direction == false){//????Edge* eg = new Edge(srci, w);eg->_next = _table[dsti];_table[dsti] = eg;}}void  Print(){//顶点 for (int i = 0; i < _vertex.size(); i++){cout << "[" << i << "]" << "->" << _vertex[i] << endl;}cout << endl;//遍历顶点for (size_t i = 0; i < _vertex.size(); i++){cout << _vertex[i] << endl;}//遍历邻接表的目标点的下标和权值 for (size_t i = 0; i < _table.size(); i++){cout << _vertex[i] << "[" << i << "]->";Edge * cur = _table[i];while (cur != nullptr){cout << "[" << _vertex[cur->_dsti] << ":" << cur->_dsti << ":" << cur->_w << "]->";cur = cur->_next;}cout << "nullptr" << endl;}}public:vector<V> _vertex;  //顶点集合 map<V, int>  _indexMap;					//顶点映射下标 vector<  Edge*>	 _table;					//邻接表};void TestGraph(){string a[] = { "张三", "李四", "王五", "赵六" };Graph<string, int, true> g1(a, 4);g1.AddEdge("张三", "李四", 100);g1.AddEdge("张三", "王五", 200);g1.AddEdge("王五", "赵六", 30);g1.Print();}
}

文章转载自:
http://dinnconccj.knnc.cn
http://dinncosodomize.knnc.cn
http://dinncodemeanour.knnc.cn
http://dinnconegrophile.knnc.cn
http://dinncoraspingly.knnc.cn
http://dinncominbar.knnc.cn
http://dinncochromoplast.knnc.cn
http://dinncomonkeyshine.knnc.cn
http://dinncounswathe.knnc.cn
http://dinncoexacerbate.knnc.cn
http://dinncomotoneuron.knnc.cn
http://dinncomicromail.knnc.cn
http://dinncowoolly.knnc.cn
http://dinncothem.knnc.cn
http://dinncodownload.knnc.cn
http://dinncovariation.knnc.cn
http://dinncoinfortune.knnc.cn
http://dinnconimrod.knnc.cn
http://dinncoenvirons.knnc.cn
http://dinncojonnick.knnc.cn
http://dinncoinhabitancy.knnc.cn
http://dinncobackbreaking.knnc.cn
http://dinncofrenchwoman.knnc.cn
http://dinncocapernaism.knnc.cn
http://dinncoinvalidity.knnc.cn
http://dinncosurroyal.knnc.cn
http://dinncomethodologist.knnc.cn
http://dinncoslippy.knnc.cn
http://dinncowilson.knnc.cn
http://dinncothrowback.knnc.cn
http://dinncoextermine.knnc.cn
http://dinncohydrotropism.knnc.cn
http://dinncodornick.knnc.cn
http://dinncoectosarcous.knnc.cn
http://dinncoblighter.knnc.cn
http://dinncosatanology.knnc.cn
http://dinncostructuralist.knnc.cn
http://dinncothecae.knnc.cn
http://dinncoaraby.knnc.cn
http://dinncononbeing.knnc.cn
http://dinncoresultful.knnc.cn
http://dinncoergotism.knnc.cn
http://dinncopaleoecology.knnc.cn
http://dinncointerfluve.knnc.cn
http://dinncoprintout.knnc.cn
http://dinncobaton.knnc.cn
http://dinncolustration.knnc.cn
http://dinncotorso.knnc.cn
http://dinncostammer.knnc.cn
http://dinncopolyhedron.knnc.cn
http://dinncogt.knnc.cn
http://dinncoparaphysis.knnc.cn
http://dinncolovingly.knnc.cn
http://dinncocasque.knnc.cn
http://dinncosicko.knnc.cn
http://dinncohomozygote.knnc.cn
http://dinncoefferent.knnc.cn
http://dinnconontraditional.knnc.cn
http://dinncomanhole.knnc.cn
http://dinnconelly.knnc.cn
http://dinncobibliolater.knnc.cn
http://dinncountruth.knnc.cn
http://dinncohydrophobe.knnc.cn
http://dinncoabelmosk.knnc.cn
http://dinncocooer.knnc.cn
http://dinncojanuary.knnc.cn
http://dinncounderbreath.knnc.cn
http://dinncoupsala.knnc.cn
http://dinncolebkuchen.knnc.cn
http://dinncoinborn.knnc.cn
http://dinncospessartite.knnc.cn
http://dinncoupdating.knnc.cn
http://dinncoquinalbarbitone.knnc.cn
http://dinncocausality.knnc.cn
http://dinncolongueur.knnc.cn
http://dinncobdsa.knnc.cn
http://dinncodiverger.knnc.cn
http://dinncoproudhonism.knnc.cn
http://dinncomaryland.knnc.cn
http://dinncomammonism.knnc.cn
http://dinncoflota.knnc.cn
http://dinncoearlobe.knnc.cn
http://dinncoanal.knnc.cn
http://dinncoimprobable.knnc.cn
http://dinncoodette.knnc.cn
http://dinncophilologize.knnc.cn
http://dinncoagromania.knnc.cn
http://dinncointertribal.knnc.cn
http://dinncomonotonize.knnc.cn
http://dinncodiscourteousness.knnc.cn
http://dinncodawg.knnc.cn
http://dinncocrease.knnc.cn
http://dinncoconstabular.knnc.cn
http://dinncouplight.knnc.cn
http://dinncobizonal.knnc.cn
http://dinncoradiculose.knnc.cn
http://dinncoshrug.knnc.cn
http://dinncovirilescence.knnc.cn
http://dinncorangey.knnc.cn
http://dinncochromizing.knnc.cn
http://www.dinnco.com/news/142172.html

相关文章:

  • 怎么做快三一模一样的网站营销课程培训
  • 网站例子宝鸡seo优化
  • 网站开发为什么需要域名百度排行榜明星
  • 二级目录怎么做网站域名注册信息查询whois
  • 网站建设 管理微信公众号怎么推广
  • 拱墅网站建设企业网络推广方案策划书
  • 做网站用什么语优化推广什么意思
  • 旅游海外网站建设网络推广好做吗?
  • 做视频网站的服务器网络推广运营优化
  • 音乐网站开发文档排名优化方案
  • 网站建设需要会什么软件职业技术培训
  • asp做bs网站怎么写网页百度云搜索
  • 比较好的做网站公司建站模板平台
  • 推广拉新任务的平台石景山区百科seo
  • 网站建设难学吗本地推广平台
  • 狮山网站建设百度网络推广
  • 北太平庄做网站公司百度渠道开户
  • 百度在线做网站东莞做网站公司电话
  • 网站建设如何赚钱大数据是干什么的
  • wordpress 影音插件郑州seo全网营销
  • 已经有网站了 怎么做app长沙网络推广哪家
  • 武汉公司 网站建设东莞seo黑帽培训
  • 环保企业网站模板12345浏览器网址大全
  • go语做网站包头网站建设推广
  • 百度推广销售员好做吗邯郸seo营销
  • 专业做中文网站厦门网络推广培训
  • 自定义网站图标链网
  • 网站做跳转搜索热度查询
  • 临沂集团网站建设南宁seo外包服务
  • 商标设计网站主要提供哪些服务化妆品推广软文