龙岗网站推广wordpress哪里设置上传大小
2026/4/15 23:44:55 网站建设 项目流程
龙岗网站推广,wordpress哪里设置上传大小,百度容易收录的网站,购物网站后台模板图 一、图的基础概念与术语概念#xff1a;图是一种非线性数据结构#xff0c;由顶点和边组成#xff0c;相较于线性关系#xff08;链表#xff09;和分治关系#xff08;树#xff09;#xff0c;网络关系#xff08;图#xff09;的自由度更高#xff0c;因而更为…图一、图的基础概念与术语概念图是一种非线性数据结构由顶点和边组成相较于线性关系链表和分治关系树网络关系图的自由度更高因而更为复杂。常见类型是否有方向无向图与有向图在无向图中边表示两顶点之间的“双向”连接关系在有向图中边具有方向性即A→B和B→A两个方向的边是相互独立的所有顶点是否连通连通图和非连通图对于连通图从某个顶点出发可以到达其余任意顶点。对于非连通图从某个顶点出发至少有一个顶点无法到达。我们还可以为边添加“权重”变量从而得到有权图术语邻接当两顶点之间存在边相连时称这两顶点“邻接”。路径从顶点 A 到顶点 B 经过的边构成的序列被称为从 A 到 B 的“路径”。度一个顶点拥有的边数。对于有向图入度表示有多少条边指向该顶点出度表示有多少条边从该顶点指出。二、图的表示邻接矩阵设图的顶点数量为 邻接矩阵使用一个 大小的矩阵来表示图每一行列代表一个顶点矩阵元素代表边用0或1表示两个顶点之间是否存在边。邻接表邻接表adjacency list使用n个链表来表示图链表节点表示顶点。第i个链表对应顶点i其中存储了该顶点的所有邻接顶点与该顶点相连的顶点。三、图的基础操作基于邻接矩阵的实现/* 基于邻接矩阵实现的无向图类 */ class GraphAdjMat { vectorint vertices; vectorvectorint adjMat; public: /* 构造方法 */ GraphAdjMat(const vectorint vertices, const vectorvectorint edges) { // 添加顶点 for (int val : vertices) { addVertex(val); } // 添加边 for (const vectorint edge : edges) { addEdge(edge[0], edge[1]); } } /* 获取顶点数量 */ int size() const { return vertices.size(); } /* 添加顶点 */ void addVertex(int val) { int n size(); vertices.push_back(val); adjMat.emplace_back(vectorint(n, 0)); for (vectorint row : adjMat) { row.push_back(0); } } /* 删除顶点 */ void removeVertex(int index) { if (index size()) { throw out_of_range(顶点不存在); } vertices.erase(vertices.begin() index); adjMat.erase(adjMat.begin() index); for (vectorint row : adjMat) { row.erase(row.begin() index); } } /* 添加边 */ // 参数 i, j 对应 vertices 元素索引 void addEdge(int i, int j) { if (i 0 || j 0 || i size() || j size() || i j) { throw out_of_range(顶点不存在); } adjMat[i][j] 1; adjMat[j][i] 1; } /* 删除边 */ void removeEdge(int i, int j) { if (i 0 || j 0 || i size() || j size() || i j) { throw out_of_range(顶点不存在); } adjMat[i][j] 0; adjMat[j][i] 0; } /* 打印邻接矩阵 */ void print() { cout 顶点列表 ; printVector(vertices); cout 邻接矩阵 endl; printVectorMatrix(adjMat); } };基于邻接表的实现/* 基于邻接表实现的无向图类 */ class GraphAdjList { public: unordered_mapVertex *, vectorVertex * adjList; /* 在 vector 中删除指定节点 */ void remove(vectorVertex * vec, Vertex *vet) { for (int i 0; i vec.size(); i) { if (vec[i] vet) { vec.erase(vec.begin() i); break; } } } /* 构造方法 */ GraphAdjList(const vectorvectorVertex * edges) { for (const vectorVertex * edge : edges) { addVertex(edge[0]); addVertex(edge[1]); addEdge(edge[0], edge[1]); } } /* 获取顶点数量 */ int size() { return adjList.size(); } /* 添加边 */ void addEdge(Vertex *vet1, Vertex *vet2) { if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 vet2) throw invalid_argument(不存在顶点); adjList[vet1].push_back(vet2); adjList[vet2].push_back(vet1); } /* 删除边 */ void removeEdge(Vertex *vet1, Vertex *vet2) { if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 vet2) throw invalid_argument(不存在顶点); remove(adjList[vet1], vet2); remove(adjList[vet2], vet1); } /* 添加顶点 */ void addVertex(Vertex *vet) { if (adjList.count(vet)) return; adjList[vet] vectorVertex *(); } /* 删除顶点 */ void removeVertex(Vertex *vet) { if (!adjList.count(vet)) throw invalid_argument(不存在顶点); adjList.erase(vet); for (auto adj : adjList) { remove(adj.second, vet); } } /* 打印邻接表 */ void print() { cout 邻接表 endl; for (auto adj : adjList) { const auto key adj.first; const auto vec adj.second; cout key-val : ; printVector(vetsToVals(vec)); } } };四、图的遍历广度优先搜索广度优先遍历是一种由近及远的遍历方式从某个节点出发始终优先访问距离最近的顶点并一层层向外扩张代码实现vectorVertex * graphBFS(GraphAdjList graph, Vertex *startVet) { vectorVertex * res; unordered_setVertex * visited {startVet}; queueVertex * que; que.push(startVet); while (!que.empty()) { Vertex *vet que.front(); que.pop(); res.push_back(vet); for (auto adjVet : graph.adjList[vet]) { if (visited.count(adjVet)) continue; que.push(adjVet); visited.emplace(adjVet); } } return res; }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询