From 6401fadc5866b989a49a7e56fc417d38ce01a551 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Fri, 10 Dec 2021 17:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=AE=E4=B8=8D=E5=A4=9A=E5=BE=97=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex11/ex11.cpp | 2 ++ ex11/graph.hpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ex11/ex11.cpp b/ex11/ex11.cpp index 34c95ff..9e07857 100644 --- a/ex11/ex11.cpp +++ b/ex11/ex11.cpp @@ -26,6 +26,8 @@ int main() case 2: printf("分别输入起始节点序号 到达节点序号 边权重:"); std::cin >> id1 >> id2 >> w; + if(id1==id2) + printf("失败\n"); switch (gv.link(id1, id2, w)) { case 0: diff --git a/ex11/graph.hpp b/ex11/graph.hpp index 51e4571..6066c9d 100644 --- a/ex11/graph.hpp +++ b/ex11/graph.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "../ex10/queue.hpp" template @@ -187,6 +188,27 @@ public: printf("\n"); } } + + virtual void BFS(int id) + { + Queue q; + + q.enqueue(id); + while (!q.empty()) + { + int vid = q.dequeue(); + + for (int j = 0; j < 100;j++) + { + if(E[id][j]!=NULL) + q.enqueue(j); + } + + // std::cout << node->pos; + printf("ID: %d",q.dequeue()); + + } + } }; #endif \ No newline at end of file