Non-recursive algorithm for breadth first (queue) and depth first (stack)

while sorQ != [] <-- sorQ is a list of lists, a list of paths if the first path in sorQ ends in the goal return this path as a solution else if the path to check in sorQ is within a length limit remove this path from sorQ "extend" the last word in this path to build another set of paths continuing from this word if this is a breadth first search add this new list of paths to the end of sorQ if this is a depth first search add this new list of paths to the beginning of sorQ