Java Tree to represent filesystem (files/dir) from list of paths

前端 未结 5 689
感动是毒
感动是毒 2021-02-04 02:39

I\'ve a list of paths like this

/mnt/sdcard/folder1/a/b/file1
/mnt/sdcard/folder1/a/b/file2
/mnt/sdcard/folder1/a/b/file3
/mnt/sdcard/folder1/a/b/file4
/mnt/sdc         


        
5条回答
  •  情书的邮戳
    2021-02-04 03:15

    Seems like you could adapt either a Trie / Radix Trie or a Binary Search Tree to work in either situation. You could augment a Trie to store "folders" as the inner nodes (instead of characters like in a regular Trie) or you could augment a Binary Search Tree to store "folders" as inner nodes (as long as they implement a comparable interface) and "files" as leaf nodes.

    My implementation of those structures are linked in the text above.

提交回复
热议问题