Iterative depth-first search using a stack data structure