NÚT CÓ GIÁ TRỊ LỚN NHẤT VÀ NHỎ NHẤT TRÊN CÂY TÌM KIẾM NHỊ PHÂN
Cấu trúc dữ liệu của cây TKNP
Code:
//Cau truc cua Node
typedef struct Node{
int info;
Node*Left;
Node*Right;
}Node;
//Dinh nghia cay nhi phan
typedef Node * Tree;
Xác định nút có giá trị lớn nhất:
Code:
//nut lon nhat trong cay
int MaxNode(Tree T) {
if( T->Right == NULL)
return T->info;
else
return MaxNode(T->Right);
}
Xác định nút có giá trị nhỏ nhất:
Code:
//nut nho nhat trong cay
int MinNode(Tree T) {
if( T->Left == NULL)
return T->info;
else
return MinNode(T->Left);
}