15 October 2022

计算机漫游

组成:

const graph={
    a:['b','c'],
    b:['d'],
    c:['e'],
    d:['f'],
    e:[],
    f:[]
}
const depthFirstPrint=(graph,source)=> {
  const stack=[source];
  whie(stack.length>0){
    const current=stack.pop();
    console.log(current);
    for(let neighbor of graph[current]){
      stack.push(neighbor);
    }

  }
};
depthFirstPrint(graph,'a')