erikpalla
3/5/2017 - 9:52 PM

Breadth-first search, Prohledavani do sirky, BFS

Breadth-first search, Prohledavani do sirky, BFS

function bfs(graph, name) {
  const queue = [...graph[name]];
  const searched = new Set();
 
  while (queue.length > 0) {
    const person = queue.shift();
 
    if (!searched.has(person)) {
      if (isSeller(person)) {
        return person;
    }
 
      queue.push(...graph[person]);
      searched.add(person);
    }
  }
  return false;
}