code refactoring

This commit is contained in:
2023-07-26 16:21:10 +02:00
parent a4d586a3a0
commit d4f656fd87
6 changed files with 20 additions and 70 deletions

View File

@@ -28,15 +28,11 @@ func DirectoryTree() (*[]string, error) {
rootPath := config.Instance().GetConfig().DownloadPath
stack := internal.Stack[Node]{
Nodes: make([]*internal.Node[Node], 5),
}
stack := internal.NewStack[Node]()
flattened := make([]string, 0)
root := Node{path: rootPath}
stack.Push(&internal.Node[Node]{
Value: root,
})
stack.Push(Node{path: rootPath})
flattened = append(flattened, rootPath)
for stack.IsNotEmpty() {
@@ -51,9 +47,7 @@ func DirectoryTree() (*[]string, error) {
if entry.IsDir() {
current.children = append(current.children, childNode)
stack.Push(&internal.Node[Node]{
Value: childNode,
})
stack.Push(childNode)
flattened = append(flattened, childNode.path)
}
}