init Graph类

This commit is contained in:
2024-12-04 22:09:22 +08:00
parent 3a3f0d4443
commit a56aa1d048
3 changed files with 57 additions and 4 deletions
+2 -1
View File
@@ -3,4 +3,5 @@ project(homework5)
set(CMAKE_CXX_STANDARD 20)
add_executable(test1 test1.cpp)
add_executable(test1 test1.cpp
Graph.h)
+27
View File
@@ -0,0 +1,27 @@
//
// Created by 31416 on 24-12-4.
//
#ifndef GRAPH_H
#define GRAPH_H
#include<vector>
using namespace std;
template<typename T>
class Graph {
private:
vector<int> ids;
Graph *node;
int max_id;
public:
Graph() {
ids.clear();
node = NULL;
max_id = 0;
}
};
#endif //GRAPH_H
+28 -3
View File
@@ -1,3 +1,28 @@
//
// Created by 31416 on 24-12-4.
//
// 利用邻接矩阵存储无向图,并从0号顶点开始进行深度优先遍历。
// 输入:
// 输入第一行是两个整数n e,其中n表示顶点数(则顶点编号为0至n-1),e表示图中的边数。之后有e行信息输入,每行输入表示一条边,格式是“顶点1 顶点2”,把边插入图中。如:
// 4 4
// 0 1
// 1 3
// 0 3
// 0 2
// 输出:
// 先输出存储图的邻接矩阵,同一行元素之间空1格,最后一个元素之后不要有空格。
// 之后空一行后输出从0号顶点开始的深度优先遍历序列,顶点编号之间空1格。
// 例如,对于上面的示例输入,输出为:
// 0 1 1 1
// 1 0 0 1
// 1 0 0 0
// 1 1 0 0
// 从顶点0开始的深度优先遍历序列:
// 0 1 3 2
// 说明
// 输入第1个4表示有4个顶点,第2个4表示有4条边。之后的4行输入代表4条边的顶点。
// 输出的前4行为邻接矩阵,之后空一行,然后输出的“0 1 3 2”是深度优先遍历序列。
# include "Graph.h"
#include<iostream>
using namespace std;
int main() {
}