defvisit(u):u.set_color("gray")forvertinu.adj:ifvert.get_color()=="white":vert.prev=upath=visit(vert)ifpath!=None:returnpathelifvert.get_color()=="blue":vert.prev=ureturnvertu.set_color("black")deffind_path(start_node):start_node.set_color("gray")start_node.prev=Nonegoal=visit(start_node)visited=[]cur=goalwhilecur!=None:visited.insert(0,cur)cur=cur.prevreturnvisited#Placeholder return to avoid errors
This lab was heavily inspired by Nathan Taylor's University of Minnesota CSCI 4041 assignment.