File creation order
I have a data structure which is shown below:
class File
{
public string Value { get; set; }
public File[] Dependencies { get; set; }
public bool Change { get; private set; }
public File(string value,File[] dependencies)
{
Value = value;
Dependencies = dependencies;
Change = false;
}
}
code>
Basically, this data structure follows typical file execution.
Each file has a value and a list of dependencies, which are again of type File. Each file displays a Change property that tells you if the file has changed.
I put my brain together to form an algorithm that goes through all of these files and builds in order (i.e. a typical build process) but doesn't have a better algorithm.
Can anyone shed some light on this?
Many thanks.
Mahesh
+2
a source to share
2 answers
Follow these basic steps.
- Finding files without any dependencies
- Add them to the first line
- Find files that depend on files in an assembly and nothing else
- Add the ones to be built like this
- Repeat 3 and 4 until all files are in assembly
You will need some checks to find circular dependencies, which will cause an infinite loop in step 5. Other than that, this should work.
+1
a source to share