Created by Wang, Jerry, last modified on Dec 18, 2015
in getAllPossibleSentences, s: catsanddog pos: 9
Sub string: catsanddog
逐一遍历字典里的word,检查当前子串是否以word结尾。
Sub String ends with word in Dict!: dog - 字典里找到一个匹配。
current position: 9 word length: 3
first Seg end: 6 找到匹配后准备开始递归。
RECURSIVELY call, new position: 6
in getAllPossibleSentences, s: catsanddog pos: 6 - 传s还是传整个字符串进去,只是position变成前6个。此时执行流不会返回,仍然是在当前dog匹配的大前提下。
Sub string: catsand
Sub String ends with word in Dict!: sand
current position: 6 word length: 4
first Seg end: 2
RECURSIVELY call, new position: 2 又找到一个匹配,再递归。
in getAllPossibleSentences, s: catsanddog pos: 2
Sub string: cat
Sub String ends with word in Dict!: cat - 再次找到匹配 dog->sand->cat
current position: 2 word length: 3
first Seg end: -1
RECURSIVELY call, new position: -1
in getAllPossibleSentences, s: catsanddog pos: -1
pos is -1, we can return now and have a rest! return result size: 1 - 这个是默认的space
result from getAllPossible with position: -1 - 从最内层的递归返回了一层。
result list’s item is STRING.space, so I directly insert end word to solution list: cat - 将最内层的cat结果加到list里。
Possible solution FOUND:!cat
insert map with position: 2 possible list: 1
[-1, “”]
[2, cat]
result from getAllPossible with position: 2
item in result list: cat - 从前一个递归insert的。Current word in dic: sand - 当前递归frame的单词。
Possible solution FOUND:!cat sand
Sub String ends with word in Dict!: and (Sub string: catsand)
current position: 6 word length: 3
first Seg end: 3
RECURSIVELY call, new position: 3
in getAllPossibleSentences, s: catsanddog pos: 3
Sub string: cats
Sub String ends with word in Dict!: cats
current position: 3 word length: 4
first Seg end: -1
RECURSIVELY call, new position: -1
in getAllPossibleSentences, s: catsanddog pos: -1
pos is -1, we can return now and have a rest! return result size: 1
result from getAllPossible with position: -1
item in result list: Current word in dic: cats
result list’s item is STRING.space, so I directly insert end word to solution list: cats
Possible solution FOUND:!cats
insert map with position: 3 possible list: 1
result from getAllPossible with position: 3
item in result list: catsCurrent word in dic: and
Possible solution FOUND:!cats and
insert map with position: 6 possible list: 2
result from getAllPossible with position: 6
item in result list: cat sandCurrent word in dic: dog
Possible solution FOUND:!cat sand dog
item in result list: cats andCurrent word in dic: dog
Possible solution FOUND:!cats and dog
insert map with position: 9 possible list: 2
result: cat sand dog
result: cats and dog