How to display flat data structure into hierarchical data structure (Java)?

前端 未结 5 1688
我在风中等你
我在风中等你 2021-02-02 15:11

I have recently faced this question in a practical test for a job .

Suppose you are given a flat data structure like this :

**Category**         **Name**         


        
5条回答
  •  别跟我提以往
    2021-02-02 15:24

    Using your ArrayList as input a recursive method will be needed to print all nodes in a hierarchical/tree representation.

    If you are not using recursion then this might be the reason that you cannot go to levels greater than the second one, that you mention.

    Some links on recursion:

    http://en.wikipedia.org/wiki/Recursion

    http://www.java-samples.com/showtutorial.php?tutorialid=151

提交回复
热议问题