, as shown in the above left in an Excel file, can't read the first line, the second line in the header of the 'level' indefinite number, the possibility of 3/4/5/... Corresponding 3/4/5 column/... Level, behind the number/name/specifications/quantity/unit five columns fixed,
Requirements: similar to the manufacturing BOM, separate the data according to the level as shown in figure in the right, Difficulty (1) parsing file 'level' number has settled through (access to the largest number of columns - 5); Difficult (2) in the order read from top down, below the level 1 only with own below level 2 and greater than level 2 skip, if appear again behind, level 1, then the second time appear behind the level 1 level 2 as the second level 1 (usually a file only a level 1). Level 2 below only with their the level 3 below, the skip of larger than level 3, if appear again later, level 2, then the second time behind the level 2 level 3 as the second level 2; Level 3 below only with their the level 4 below, the skip of larger than level 4, if appear again behind, level 3, then the second time in level 3 at the back of the level 4 as the second level 3; So on, Difficulty (3) the last hope to List List=new ArrayList (a); Type of storage, will split the independence of each group,
Himself wrote a two days this logic... Feel how write all cannot solve the level 3 only to appear in the last 2, meet next 2 jump out, and then continue to split a Everybody a great god help see can solve, thank you thank you!
CodePudding user response:
CodePudding user response:
You can't read while the output, should complete the data read into memory first. In the memory, can use Map Way of recording data, the key is level, List Is the level of the index value of the collection order (from top to bottom), After reading, you save your map global information. Can recursively, incoming call recursive method two parameters: the level=1, level 1 index=0, + 1=2, then the key take 2 have to judge the following list, if any, traverse the level 2, and then call the recursive method is introduced to level 2, level 2 instead of the index, the recursive until decision condition is level 5, this time at level 5, the participation in do you know how much is the index of level 4, with the index of level 4, to find his next index. You'll get the table row index of the scope of level 5. Can split out the lowest table.