I'm making a program which the user build directories (not in windows, in my app) and in these folders there are subfolders and so on; every folder must contain either folders or documents. What is the best data structure to use? Notice that the user may select a subfolder and search for documents in it and in its subfolders. And I don't want to limit the folders or the subfolders levels.
相关问题
- How to access the camera from my Windows Phone 8 a
- C++ a class with an array of structs, without know
- Character.getNumericvalue in char Frequency table
- Quickest method for matching nested XML data again
- QMap but without sorting by key
相关文章
- Is there an existing solution for these particular
- Systematically applying a function to all fields o
- Directory.CreateDirectory Latency Issue?
- Why can we add null elements to a java LinkedList?
- How can i list only the folders in zip archive in
- Is Heap considered an Abstract Data Type?
- Python Imports From The Directory Above
- Scala variadic functions and Seq
Most OO languages come with some sort of abstraction for the file system, so there is where I would start. Then subclass it if you need to.
I would expect directories as an array of objects which are directories or files, for instance.
I know that the question is specifically asking for a data structure but...
If you are using an object oriented language maybe you can use the composite design pattern which is ideally suited for this type of hierarchical tree like structure. You get what you are asking for.
you can use m-way tree data structure
I should recommend B+ Tree .... You can easily use indexing (page,folder etc ) and all .
B+ Tree http://commons.wikimedia.org/wiki/File:Btree.png
for more info : http://ozark.hendrix.edu/~burch/cs/340/reading/btree/index.html
This is what I do:
Every record in the database has two fields: ID and ParentID. IDs are 4-5 characters (Base36, a-z:0-9 or something similar). Parent IDs are a concatenation of the parent's complete structure...
So...
This structure:
Would be represented like this:
I like this structure because if I need to find all the files under a folder I can do a query like:
To delete a folder and all its children:
To move a folder and its children, you have to update all the records that use the same parent, to the new parent.
An obvious limitation to this is that the number of subfolders are limited to the size of your ParentID field.
I would look into using some sort of tree data structure