breadthfirst (takes in graph and source)
make a bool visited array, calloc it to the num verticies in graph
make a predecessor array, caclloc it to num vertices (int)
Make a new queue.
set visited of the source to true
Enqueue source,
while queue isnt empty
int v = dequeue
print v
now in a for loop iterating until num vertices: loop counter w:
if graph edges[v][w] && !visited[w]
then make visited of w true
make the pred of w = v
enqueue q,w
out of all loops
free visited, pred, queue.
DEPTHFIRST: takes in graph, int source
difference is this uses a stack.
calloc a bool visited array to num verticies
same with int predecessor
create a stack
push stack of source
While stack isnt empty:
int v = stackpop(s)
if visited[v] continue:
set the visited of v to true
print v and a newline
in a for loop for loop counter w set to numvertices - 1, up until w>=0 w--
if graphedges[v][w] and !visited[w] then:
set the predecessor of w = w
stackpush w
out of all the loops,
free visited, predecessor and stack.