728x90
[ 자료구조 ] inorder preorder postorder traversal 탐색 알고리즘
1. 중위 탐색 (inorder traversal) 알고리즘 , 왼나오
중위 탐색 트리 알고리즘은 순환 알고리즘이 간단하다.
void inorder(tree_ptr ptr) {
if(ptr) {
inorder(ptr->left_child);
printf(“%d”,ptr->data);
inorder(ptr->right_child);
}
}
2. 전위 탐색 (preorder traversal) , 나왼오
순환 알고리즘이다, 전위 탐색으로 모든 트리를 탐색한다.
void inorder(tree_ptr ptr) {
if(ptr) {
printf(“%d”,ptr->data);
inorder(ptr->left_child);
inorder(ptr->right_child);
}
}
3. 후위 탐색 (postorder traversal) , 왼오나
순환 알고리즘이다, 후위 탐색으로 모든 트리를 탐색한다.
void inorder(tree_ptr ptr) {
if(ptr) {
inorder(ptr->left_child);
inorder(ptr->right_child);
printf(“%d”,ptr->data);
}
}
728x90
'CS > 자료구조' 카테고리의 다른 글
[ 자료구조 ] level order iterative inorder tree traversal (1) | 2021.11.29 |
---|---|
[ 자료구조 ] Tree Linked List로 구현하기 (2) (0) | 2021.11.27 |
[ 자료구조 ] Tree Linked List로 구현하기 (1) (1) | 2021.11.26 |
[ 자료구조 ] Skewed 이진트리 포화 이진트리 완전 이진트리 (0) | 2021.11.25 |
[ 자료구조 ] 이진트리 Binary Tree (0) | 2021.11.24 |