MJinH commented on issue #44:
URL: https://github.com/apache/age-viewer/issues/44#issuecomment-1284089213

   Code for BFS
   ```
   const bfs = (graph, node) => {
     let visited = [];
     let nodes= [];
   
     nodes.push(node); 
   
     while (nodes.length !== 0) { 
       const newNode = nodes.shift(); 
       if (!visited.includes(newNode )) {
         visited.push(newNode ); 
         nodes= [...nodes, ...graph[newNode ]];
       }
     }
     return visited;
   };
   ````
   
   Code for DFS
   ```
   const dfs = (graph, node) => {
     let stack= [];
     let queue= [];
   
     stack.push(node);
   
     // 탐색을 해야 할 노드가 남아 있다면
     while (stack.length !== 0) {
       const newNode = stack.pop();
       if (!queue.includes(newNode )) {
         queue.push(newNode );
         stack= [...stack, ...graph[newNode]];
       }
     }
     return queue;
   };
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to