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