[Solved] Function receiving different value than passed

At least part of the problem is that you are not understanding how operators work in C++. for(i=1;i<=n,completed==0;i++){ The expression i<=n,completed==0 has the effect of evaluating i <= n, discarding the result, then evaluating completed == 0, and giving the result of that. So the end condition of the loop is essentially completed == 0. … Read more

[Solved] Depth first or breadth algorithm in adjacency List [closed]

You can implement adjacency list with vectors like this, it is much easier than using pointers. Check the code, it is also much easier to understand how it works. #include <bits/stdc++.h> using namespace std; vector<int> edges[5]; bool visited[5]; void dfs(int x) { visited[x] = true; for(int i=0; i < edges[x].size(); i++) if(!visited[edges[x][i]]) dfs(edges[x][i]); } int … Read more

[Solved] C++ – DFS code error

The problem is that you haven’t coded DFS-VISIT step 4 correctly Step 4 says for each v ∈ G.Adj[u] but your code says for(int i=0; i<G; i++). Those aren’t the same thing at all. You should only visit the adjacent vertexes. In fact if you look at your code you never use adj at all. … Read more