2025年广度优先搜索和深度优先搜索一样吗(广度优先搜索和深度优先搜索一样吗)

广度优先搜索和深度优先搜索一样吗(广度优先搜索和深度优先搜索一样吗)1 2 3 param target 目标节点 要在哪个节点里面进行搜索 4 param prop 搜索索引 5 索引条件在 isLegal 里面进行修改 6 7 function breadthSearc target 8 const nodeList target 9 let index 0 10 while index lt nodeList length 11 const node



 1 /**
 2  * 
 3  * @param {*} target: 目标节点,要在哪个节点里面进行搜索
 4  * @param {*} prop: 搜索索引
 5  * 索引条件在isLegal()里面进行修改
 6  */
 7 function breadthSearch(target){
 8     const nodeList = [target];
 9     let index = 0;
10     while (index < nodeList.length) {
11         const node = nodeList[index++];
12         if (node.children && node.children.length > 0) {
13             for (let k in node.children) {
14                 nodeList.push(node.children[k]);
15             }
16         }
17     }
18     return function(prop) {
19         let targetNodeList = [];
20         for (let node of nodeList) {
21             if(isLegal(node, prop)) {
22                 targetNodeList.push(node);
23             }
24         }
25         return targetNodeList;
26     }
27 }
编程小号
上一篇 2025-03-02 13:57
下一篇 2025-03-01 17:01

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/38538.html