Need make a TOC from next example String:
Input
`#` Sport
common text
`##` Tennis
`###` Table
`###` Ping Pong
commontext
`#` Dance
Output
Sport 1
common text
Tennis 1.1
Table 1.1.1
Ping Pong 1.1.2
commontext
Dance 2
etc
My one solution via Map and recursive substring Pastebin - https://pastebin.com/DqcsGKTu. But i think its may work with Composite design pattern cause its looks like tree. Someone have idea for it? First try to use tree structure https://pastebin.com/u54MQ88x - clien and logic, https://pastebin.com/fh4yVKXM - tree model. It doesnt work correctly cause printing Dance 1.2 not Dance 2.
Aucun commentaire:
Enregistrer un commentaire