0
안녕하세요. 해결할 수없는 문제가 발생했습니다. 나는 BST를 통과하여 랭킹을 점검하고있다. 나는 머리 노드를 가져 와서 targRank와 동일한 순위를 가진 노드를 찾을 때까지 트리를 가로 지르는 방법 checkRank(link head, targRank)
을 가지고있다. 내가 뭘 하려는지 checkRank 함수가 동일한 순위를 찾은 현재 노드를 반환하는 것입니다. 모든 시도가 현재 노드를 머리로 반환하는 것처럼 보이기 때문에이를 달성하는 가장 좋은 방법은 무엇입니까?BST에서 현재 노드 반환
typedef struct node* link;
struct node
{
Item item; // Data for this node
link l, r; // left & right links
int rank;
};
Func을 호출 :
link head;
checkRank(head, 13);
Func을 : 모든
link checkRank(link h,int targetRank)
{
if (h != NULL)
{
if (h->rank < targRank)
{
checkRank(h->r, targRank);
}
if (h->rank > tarRank)
{
checkRank(h->l, targtRank);
}
if (h->rank == targRank)
{
return ??;
}
}
else
{
printf("Equiv rank could not be found\n");
}
}
예. 고맙습니다. – bardockyo