-1

Input: ( 10 ( 4 20 ( 2 ) 13 ( 16 ( 3 ) ) ) 5 12 7 ( 17 ( 9 ( 19 15 ) 8 ) 6 ) 11 )

Output:Multilevel Linked Lists

1 Answers1

1

The solution will almost certainly be a recursive one.

Given a node definition, you will need a payload (the number), a next pointer (for items at the same "level") and an under pointer (for the sub-list).

So you simply iterate over the incoming tokens. When you find a number, you tack it on to the next pointer of the previous one (special handling for empty list).

When you find an opening parenthesis followed by a number, you put it in the under link and recurse down a level.

When you find a closing parenthesis, go back up a level and carry on.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953