Traverse to the deepest using Java

前端 未结 2 970
再見小時候
再見小時候 2021-01-06 00:59

I have a data structure like below:

Task(id,name,subTasks[Task])

But the problem is the subTasks can contain Tasks which have another subTa

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 01:35

    Data structure: the implicit tree formed by object references.

    Traversal: recursion or queues.

    However, you will have to consider each use case individually. Some will call for depth-first traversal, some for breadth-first traversal. Consider using some graph library to build the trees in the first place if you need a lot of graph operations.

提交回复
热议问题