BFS-DFS概要总结 Posted on 2017-10-20 | BFS, DFS最概要的总结转自stackoverflow DFS: 123456list nodes_to_visit = {root};while( nodes_to_visit isn't empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.prepend( currentnode.children ); //do something} BFS: 123456list nodes_to_visit = {root};while( nodes_to_visit isn't empty ) { currentnode = nodes_to_visit.take_first(); nodes_to_visit.append( currentnode.children ); //do something} 注意唯一的区别就是DFS是prepend,添加在最前。而BFS是append,添加在最后。