cpp-algo-cases/chapter_graph/graph_adjacency_list_test.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

2024-02-20 16:13:23 +08:00
/**
* File: graph_adjacency_list_test.cpp
* Created Time: 2023-02-09
* Author: what-is-me (whatisme@outlook.jp), krahets (krahets@163.com)
*/
#include "./graph_adjacency_list.cpp"
/* Driver Code */
int main() {
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ */
vector<Vertex *> v = valsToVets(vector<int>{1, 3, 2, 5, 4});
vector<vector<Vertex *>> edges = {{v[0], v[1]}, {v[0], v[3]}, {v[1], v[2]},
{v[2], v[3]}, {v[2], v[4]}, {v[3], v[4]}};
GraphAdjList graph(edges);
cout << "\n<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼΪ" << endl;
graph.print();
/* <20><><EFBFBD>ӱ<EFBFBD> */
// <20><><EFBFBD><EFBFBD> 1, 2 <20><> v[0], v[2]
graph.addEdge(v[0], v[2]);
cout << "\n<EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD> 1-2 <20><><EFBFBD><EFBFBD>ͼΪ" << endl;
graph.print();
/* ɾ<><C9BE><EFBFBD><EFBFBD> */
// <20><><EFBFBD><EFBFBD> 1, 3 <20><> v[0], v[1]
graph.removeEdge(v[0], v[1]);
cout << "\nɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1-3 <20><><EFBFBD><EFBFBD>ͼΪ" << endl;
graph.print();
/* <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD> */
Vertex *v5 = new Vertex(6);
graph.addVertex(v5);
cout << "\n<EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD> 6 <20><><EFBFBD><EFBFBD>ͼΪ" << endl;
graph.print();
/* ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
// <20><><EFBFBD><EFBFBD> 3 <20><> v[1]
graph.removeVertex(v[1]);
cout << "\nɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3 <20><><EFBFBD><EFBFBD>ͼΪ" << endl;
graph.print();
// <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
for (Vertex *vet : v) {
delete vet;
}
return 0;
}