You are going to compile several source code files, but there are dependencies between them. What is the order to compile them?
e.g.
A import B, C
B import C
We can follow the order of C, B, A.
First, we need to model this kind of dependencies into a graph. I think we can use the adjacency list to represent this graph. Because if we are finding the dependency in the source code files the dependency should be a sparse graph. Thus, using an adjacency matrix would be a waste of space.
Assume we don’t have a cycle dependency because that means we couldn't give an order.
To represent the source file we can use a class, and our input can be a List, and we need to output a List.
I think we are going to use topological sort to solve this problem.