March 26th, 2013, 09:52 AM
I really wanna understand how this code works
it's a program to implement depth first search
#define MAX 5
int dfs(int adj[MAX], int visited, int start)
printf("DFS Traversal : ");
I would be grateful if you helped me!!!
March 26th, 2013, 11:23 AM
The adjacency matrix stores the graph.
where a 1 indicates a directed connection of nodes. The matrix isn't symmetric.
a b c d e
a|0 0 1 1 0
f b|0 0 0 0 0
r c|0 1 0 1 1
o d|0 0 0 0 1
m e|0 0 0 1 0
The stack holds the frontier---the list of the nodes accessible from nodes visited. But because of the break statement the stack gets only the next node on the frontier. And continues with the new start position. Eventually the stack pops back when the code can continue to look for additional nodes on the frontier of a previous start node.
Last edited by b49P23TIvg; March 26th, 2013 at 12:13 PM.
[/code] are essential for python code and Makefiles!
March 26th, 2013, 03:37 PM
The best way to do that is to single-step the code in your debugger.
Originally Posted by fun girl
You could learn the fundamentals of the debugger - stepping, watching, and breakpoints in about the time you spent posting this question and reading the answers, but the lesson will pay back many times over in code debugging, testing and comprehension. The return on investment will easily break-even the first time you use it on this code in that say it took you an hour to figure it out manually, with half an hour debugger familiarisation, it will then take you less than half an hour to achieve the same level of comprehension with the debugger, and next time you already know how to use the debugger.