v7
This commit is contained in:
@@ -6,22 +6,23 @@ main(){
|
||||
/// 输出节点 2, 2-3,2-3-1
|
||||
// findNodes(root, '2-2', 0,'');
|
||||
// List<Node> nodes = findNodes(root, '2-3-1', 0,'',[]);
|
||||
List<Node> nodes = find( '/2/3/1');
|
||||
// List<Node> nodes = find( '/2/3/1');
|
||||
List<Node> nodes = find( '/4/3/4');
|
||||
print(nodes);
|
||||
}
|
||||
|
||||
List<Node> find(String input){
|
||||
String fixInput = input.substring(1);
|
||||
List<Node> nodes = findNodes(root2,fixInput,0,'/',[]);
|
||||
if(nodes.isNotEmpty&&nodes.last.value!=input){
|
||||
return [];
|
||||
}
|
||||
|
||||
List<Node> nodes = findNodes(root2,Uri.parse(input),0,'/',[]);
|
||||
// if(nodes.isNotEmpty&&nodes.last.value!=input){
|
||||
// return [];
|
||||
// }
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
||||
List<Node> findNodes(Node node,String input,int deep,String prefix,List<Node> result){
|
||||
List<String> parts = input.split('/');
|
||||
List<Node> findNodes(Node node,Uri uri,int deep,String prefix,List<Node> result){
|
||||
List<String> parts = uri.pathSegments;
|
||||
if(deep>parts.length-1){
|
||||
return result;
|
||||
}
|
||||
@@ -33,10 +34,11 @@ List<Node> findNodes(Node node,String input,int deep,String prefix,List<Node> re
|
||||
Node matched = nodes.first;
|
||||
result.add(matched);
|
||||
String nextPrefix = '${matched.value}/';
|
||||
findNodes(matched, input, ++deep,nextPrefix,result);
|
||||
findNodes(matched, uri, ++deep,nextPrefix,result);
|
||||
}else{
|
||||
result.add(Node(value: 'error'));
|
||||
return result;
|
||||
}
|
||||
}else{
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user