Demo entry 3539909

bfs_visited

   

Submitted by anonymous on Jan 11, 2016 at 09:17
Language: Python. Code size: 646 Bytes.

def bfs_paths_visited(graph, start, goal, level_lines):
    stack = [(start, [start])]
    visited = [start]
    while stack:
        #print "while", len(stack)
        (vertex, path) = stack.pop(0) #remove and return first item
        for next in graph[vertex]:
            if next not in visited:
                visited.append(next)
                #print len(visited),next
                #print_board(next[1],next[0],goal[0],level_lines)
                if next[0] == goal[0]:
                    return path + [next]
                else:
                    stack.append((next, path + [next]))
    print "stack empty"    

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).