당신은 다른 이진 검색 나무의 계층 구조로 삼항 검색 트리 생각할 수
- 검은 선이 같은 BST 함께 노드를 연결하고, 점선 링크 서로 다른 BST를 함께 사용하십시오.
수정 된 inorder 순회를 수행하여 TST의 모든 단어를 나열 할 수 있습니다. 특히, inorder traversal을 수행하고 각 노드에서 현재 노드에 연결된 TST의 모든 단어를 재귀 적으로 나열합니다. 앞에는 경로에있는 문자가 앞에 붙습니다. 이 도움이
function tst_inorder_traversal(node) {
_tst_inorder_traversal_aux(node, "");
}
function _tst_inorder_traversal_aux(node, prefix) {
if (node is not null) {
/* Start normal in-order traversal.
This prints all words that come alphabetically before the words rooted here.*/
_tst_inorder_traversal_aux(node->left, prefix);
/* List all words starting with the current character. */
if (node marks the end of the word)
print(prefix + tree->character);
_tst_inorder_traversal_aux(node->middle, prefix + node->character);
/* Finish the in-order traversal by listing all words that come after this word.*/
_tst_inorder_traversal_aux(node->right, prefix);
}
}
희망 :
는 여기에 몇 가지 의사 코드입니다!
'tree-> child'는 점선 (가운데 자식)입니다. 'tree-> node'는 오타였습니다; 현재 노드와 연관된 문자 인'tree-> character'이어야합니다. – templatetypedef