Skip to content

bfsByLoop

广度优先遍历-循环的方式

配置项

参数类型是否必选默认值参数描述
nodesArray-源数组
callbackFunction-回调函数,接收当前节点数据

返回值

类型描述
void-

示例

// 待补充

源码

js
export function bfsByLoop(nodes, callback) {
    let node, curTree = nodes;
    while ((node = curTree.shift())) {
        callback(node);
        if (node.children) {
            curTree.push(...node.children);
        }
    }
}