나는이 문제를 생각해 봤지만 좋은 해결책은 찾지 못했습니다.이진 트리에서 주어진 노드 (또는 항목)의 미러 노드를 효율적으로 찾는 방법
이진 트리에서 주어진 노드 (또는 항목)의 미러 노드를 찾는 방법은 무엇입니까?
// Node definition
struct _Node {
char data;
struct _Node* left;
struct _Node* right;
} Node;
// Assumption:
// "given" is guaranteed in the binary tree ("root" which is not NULL)
Node* FindMirrorNode(Node* root, Node* given)
{
// Implementation here
}
// OR:
// Assumption:
// in the binary tree ("root"), there is no repeated items, which mean in each node the char data is unique;
// The char "given" is guaranteed in the binary tree.
char FindMirrorNodeData(Node* root, char given)
{
// Implementation here
}
참고 : 나는
For example, considering the tree below
A
/ \
B C
/ / \
D E F
\ /\
G H I
The mirror node of 'D' is node 'F'; while the mirror node of 'G' is NULL.
감사합니다 :-) 주어진 트리의 미러 트리를 찾는 방법에 대한 요구 아니에요.
이 바보 같은 질문이 될 수도 있지만 당신은 미러 노드 또는 그것의 정의에 적어도 링크를 어떻게 설명 할 수 있을까? –
Hi Mark, 네, 맞습니다. 바보 같은 질문 일지 모르지만, 이진 트리를 더 잘 이해하기 위해서는 좋은 습관이 될 수도 있습니다 :-) 고마워요. 미러 노드 정의의 예를 추가했습니다. –