Format C++ codes in Clang-Format Style: Microsoft

This commit is contained in:
krahets
2023-04-14 03:44:02 +08:00
parent f8513455b5
commit 9c9c8b7574
46 changed files with 732 additions and 888 deletions

View File

@@ -8,13 +8,13 @@
#include "./graph_adjacency_list.cpp"
/* 深度优先遍历 DFS 辅助函数 */
void dfs(GraphAdjList& graph, unordered_set<Vertex*>& visited, vector<Vertex*>& res, Vertex* vet) {
void dfs(GraphAdjList &graph, unordered_set<Vertex *> &visited, vector<Vertex *> &res, Vertex *vet) {
res.push_back(vet); // 记录访问顶点
visited.emplace(vet); // 标记该顶点已被访问
// 遍历该顶点的所有邻接顶点
for (Vertex* adjVet : graph.adjList[vet]) {
for (Vertex *adjVet : graph.adjList[vet]) {
if (visited.count(adjVet))
continue; // 跳过已被访问过的顶点
continue; // 跳过已被访问过的顶点
// 递归访问邻接顶点
dfs(graph, visited, res, adjVet);
}
@@ -22,11 +22,11 @@ void dfs(GraphAdjList& graph, unordered_set<Vertex*>& visited, vector<Vertex*>&
/* 深度优先遍历 DFS */
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
vector<Vertex*> graphDFS(GraphAdjList& graph, Vertex* startVet) {
vector<Vertex *> graphDFS(GraphAdjList &graph, Vertex *startVet) {
// 顶点遍历序列
vector<Vertex*> res;
vector<Vertex *> res;
// 哈希表,用于记录已被访问过的顶点
unordered_set<Vertex*> visited;
unordered_set<Vertex *> visited;
dfs(graph, visited, res, startVet);
return res;
}
@@ -34,17 +34,17 @@ vector<Vertex*> graphDFS(GraphAdjList& graph, Vertex* startVet) {
/* Driver Code */
int main() {
/* 初始化无向图 */
vector<Vertex*> v = valsToVets(vector<int> { 0, 1, 2, 3, 4, 5, 6 });
vector<vector<Vertex*>> edges = { { v[0], v[1] }, { v[0], v[3] }, { v[1], v[2] },
{ v[2], v[5] }, { v[4], v[5] }, { v[5], v[6] } };
vector<Vertex *> v = valsToVets(vector<int>{0, 1, 2, 3, 4, 5, 6});
vector<vector<Vertex *>> edges = {{v[0], v[1]}, {v[0], v[3]}, {v[1], v[2]},
{v[2], v[5]}, {v[4], v[5]}, {v[5], v[6]}};
GraphAdjList graph(edges);
cout << "\n初始化后,图为" << endl;
graph.print();
/* 深度优先遍历 DFS */
vector<Vertex*> res = graphDFS(graph, v[0]);
vector<Vertex *> res = graphDFS(graph, v[0]);
cout << "\n深度优先遍历DFS顶点序列为" << endl;
PrintUtil::printVector(vetsToVals(res));
printVector(vetsToVals(res));
// 释放内存
for (Vertex *vet : v) {