path method
返回从当前节点到指定节点的最短路径
Implementation
List<T> path(T target) {
T? start = this as T;
T? end = target;
T? ancestor = minCommonAncestor(start, end);
List<T> nodes = [start];
while (ancestor != start) {
start = start?.parent;
if (start != null) {
nodes.add(start);
}
}
var k = nodes.length;
while (end != ancestor) {
nodes.insert(k, end!);
end = end.parent;
}
return nodes;
}