DSA-Assignments

Log | Files | Refs | README

commit 471baade26f3531eaec7679388dbbc4a60b559f8
parent d68ce4dd3430ece023a2b550f9c534b60a7f4e24
Author: a20vicad <vicada0203@gmail.com>
Date:   Thu, 30 Nov 2023 17:22:38 +0100

Changed list to queue

Diffstat:
MProblem2/Problem2.cpp | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Problem2/Problem2.cpp b/Problem2/Problem2.cpp @@ -39,8 +39,8 @@ bool Graph::isEdge(int v, int w) { if (w == *i) { return(true); } - return(false); } + return(false); } int Graph::getNumNodes() { @@ -61,19 +61,19 @@ void Graph::BFS(int v) vector<bool> visited; visited.resize(V, false); - list<int> queue; + queue<int> queue; visited[v] = true; - queue.push_back(v); + queue.push(v); while (!queue.empty()) { v = queue.front(); cout << v << " "; - queue.pop_front(); + queue.pop(); for (auto adjacent : adj[v]) { if (!visited[adjacent]) { visited[adjacent] = true; - queue.push_back(adjacent); + queue.push(adjacent); } } } @@ -87,7 +87,7 @@ int main(){ network.addEdge(2, 3); //C dislikes D network.addEdge(2, 1); //C dislikes B network.printGraph(); - + const int i = network.getNumNodes(); list<int> nodes[4]; cout << "\n" << "Number of nodes: " << i << "\n";