Reputation: 1
I have a List<Object>
and each Object has integer 'id' and integer 'depends' parameter. This list then goes for some processing such that the objects which are not dependent on anyone will do the processing first and then next group of objects go ahead.
I have implemented this using topology sort along with adjacency list which does the job beautifully, but I am being told to use tree (TreeModel) as the previous approach is difficult to understand. The independent objects will be at root level, the object depending on it will be its children and so on. So, all objects at root level will go first, then object at level 2 and then 3...
I am a little confused as to how I would proceed with the implementation. I am thinking I would start with List<TreeModel<Object>>
, so each index represents a tree and then form the trees accordingly. And while parsing, I will parse all the root level first, then the 2nd level and then 3rd.. Though I think there is an elegant way.
Any hint/ help would be appreciated. Thanks.
Upvotes: 0
Views: 47