const tree = {
val: 'a',
children: [
{
val: 'b',
children: [
{
val: 'd',
children: [
{
val: 'h',
children: [],
},
{
val: 'i',
children: [],
},
],
},
{
val: 'e',
children: [
{
val: 'j',
children: [],
},
{
val: 'k',
children: [],
},
],
},
],
},
{
val: 'c',
children: [
{
val: 'f',
children: [
{
val: 'l',
children: [],
},
{
val: 'm',
children: [],
},
],
},
{
val: 'g',
children: [
{
val: 'n',
children: [],
},
{
val: 'o',
children: [],
},
],
},
],
},
],
};
求教老师,这个数据结构,能否用递归的方式去做广度优先遍历?我想了好久都没想出来
用队列是我是OK的,队列就适合这种明确有序的遍历