Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar11 / bfs-dfs.cpp
diff options
context:
space:
mode:
Commit7eee5a78005a9a569186d2c8b4b645a818ab9bf1 (patch)
Author
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-06 07:04:44 -0400
Committer
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-06 07:04:44 -0400
Files84594e0af29cefa5aae76ace5f8eb81484400e31 /Seminar11/bfs-dfs.cpp
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.tar
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.tar.gz
Data-structures-and-algorithms-7eee5a78005a9a569186d2c8b4b645a818ab9bf1.zip
Parent0841635826cb03c0e74cd75ec3c97c4c3b594d8b (diff)
Cleanup
1 files changed, 0 insertions, 65 deletions
-rw-r--r--Seminar11/bfs-dfs.cpp65
diff --git a/Seminar11/bfs-dfs.cpp b/Seminar11/bfs-dfs.cpp
deleted file mode 100644
index 75a6f3d..0000000
--- a/Seminar11/bfs-dfs.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include<iostream>
-#include"Graph-Impl/AdjacencyListGraph/AdjListGraph.h"
-#include"Graph-Impl/MatrixGraph/MatrixGraph.h"
-#include<queue>
-
-void BFS(const MatrixGraph& g, MatrixGraph::vertex_t start) {
- std::vector<bool> visited(g.vertexCount(), false);
-
- std::queue<MatrixGraph::vertex_t> q;
-
- q.push(start);
-
- while(!q.empty()) {
- MatrixGraph::vertex_t current = q.front();
- q.pop();
-
- if(visited[current])
- continue;
-
- visited[current] = true;
-
- std::cout << current << " ";
-
- auto successors = g.getSuccessors(current);
-
- for(const auto& currentVertex : successors) {
- if(!visited[currentVertex])
- q.push(currentVertex);
- }
- }
-}
-
-void DFSRec(std::vector<bool>& visited, const AdjListGraph& g, AdjListGraph::vertex_t start) {
- visited[start] = true;
-
- auto child = g.adjacent(start);
-
- std::cout << "Visited " << start << std::endl;
-
- for(const auto& currChild : child) {
- if(!visited[currChild.to]) {
- DFSRec(visited, g, currChild.to);
- }
- }
-}
-
-void DFS(const AdjListGraph& g, AdjListGraph::vertex_t start) {
- std::vector<bool> visited(g.vertexCount(), false);
- DFSRec(visited, g, start);
-}
-
-
-int main() {
- // MatrixGraph g(5);
- AdjListGraph g(5);
- g.addEdge(0, 2, 1);
- g.addEdge(0, 3, 1);
- g.addEdge(0, 1, 1);
- g.addEdge(2, 3, 1);
- g.addEdge(1, 4, 1);
- g.addEdge(3, 4, 1);
- g.addEdge(1, 3, 1);
-
- DFS(g, 0);
-} \ No newline at end of file