以下代码结果运行结果是什么?为什么?
let cache,
result = Infinity;
function fun(tree) {
if (!tree) return;
fun(tree.left);
if (cache) {
result = Math.min(result, Math.abs(cache - tree.value));
}
cache = tree.value;
fun(tree.right);
}
const tree = {
value: 90,
left: {
value: 50,
left: {
value: 20,
left: {
value: 5,
left: null,
right: null
},
right: {
value: 25,
left: null,
right: null
}
},
right: {
value: 75,
left: {
value: 66,
left: null,
right: null
},
right: {
value: 80,
left: null,
right: null
}
}
},
right: {
value: 150,
left: {
value: 95,
left: {
value: 92,
left: null,
right: null
},
right: {
value: 111,
left: null,
right: null
}
},
right: {
value: 175,
left: {
value: 166,
left: null,
right: null
},
right: {
value: 200,
left: null,
right: null
}
}
}
};
fun(tree);
console.log(result);