I replace the venerable
make utility that will support, among other things, automatic cleaning. The utility automatically determines which files and directories are targets, and then deletes them if the user wants to perform a cleanup operation. However, a file can reside in an automatically created directory, which means that I should perform topological sorting of targets. Each file has an arc to the parent directory and each directory has an arc to its parent. So, for example:
objhierarchy/obj/foo.ohas a bow towards
objhierarchy/objhas a bow towards
What complicates things is that the files must be deleted in the reverse order. So, in the given example, you need this order: (1)
The topological type seems to be a good solution, but it gives the opposite order. Thus, a topological kind of the parent graph of the repertoire would give (1)
One solution might be a reverse pointer buffer in place (or simply iterated in the reverse order), but I would like to avoid allocating additional memory.
What is the best way to delete files in the reverse order? Can the topological sort algorithm based on the first depth search be modified to call a callback function in reverse order?