Successful solution to 7.1.
This commit is contained in:
parent
f6ea56d266
commit
7f0bc4d9f1
2 changed files with 36 additions and 42 deletions
|
@ -39,16 +39,15 @@ func BuildDependencyTree(data []string) *Node {
|
|||
|
||||
// sort the children in each node
|
||||
for _, node := range depMap {
|
||||
sortChildren(node)
|
||||
sortNodes(node.Children)
|
||||
}
|
||||
|
||||
return BuildTreeRoot(depMap)
|
||||
}
|
||||
|
||||
func sortChildren(node *Node) {
|
||||
children := node.Children
|
||||
sort.Slice(children[:], func(i, j int) bool {
|
||||
return children[i].Name < children[j].Name
|
||||
func sortNodes(nodes []*Node) {
|
||||
sort.Slice(nodes[:], func(i, j int) bool {
|
||||
return nodes[i].Name < nodes[j].Name
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -62,6 +61,6 @@ func BuildTreeRoot(depMap map[rune]*Node) *Node {
|
|||
}
|
||||
}
|
||||
|
||||
sortChildren(root)
|
||||
sortNodes(root.Children)
|
||||
return root
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue