I guess you could do it by maintaining a stack and a visited-list, and using a while-loop:
Visited is a bool[], initialized to hold false at all positions, and I assume that the call G[node,neighbour] somehow returns a boolean, telling if there is an edge from node to neighbour. (Implicit comparison to 1 or simply make the adjacency matrix hold booleans)
Stack holds the indices of your nodes:
dfs(G,i){
Initialize Stack
Current = i
PossibleEdge = 0
Visited[Current] = true //You have visited the starting node
Do {
While (PossibleEdge < count) {
if (G[Current,PossibleEdge] && NOT Visited[PossibleEdge]){
Stack.Push(Current) //Save state
Current = PossibleEdge //Continue with the child node
Visited[Current] = true
PossibleEdge = -1 //So that it will be incremented to 0
}
PossibleEdge++
}
PossibleEdge = Current //Continue to next row of "parent node"
Current = Stack.Pop() //Get parent node back
} While (Stack contains nodes)
}
I'm sure it could be optimized (and seeing that I'm dead tired, there might be some logical errors), but if the basic procedure makes sense, it's a start!
EDIT: Clarifying, and adding this tip: Recursion is probably easier ;)