با سلام
موضوع:تابع پیدا کردن ماکزیمم و مینیمم در درخت دودویی
void SearchTree ( TREE* treeptr, int min, int max, int &n)
{
if (treeptr != NULL)
{
if (treeptr->info <= max) && (treeptr->info >= min)
{
++n; // One value in the range, so increase the counter
searchTree(&treeptr->left, min, max, n);
searchTree(&treeptr->right, min, max, n);
}
else if (treeptr->info > max) {
searchTree(tree->left,min,max, n);
} else {
searchTree(tree->right, min, max, n);
}
}
}
یا
struct tree {
int data1,data2;
tree* left;
tree* right;
} * TREE;
void findData2Max (TREE* t, int& max)
{
if (t != NULL)
{
if (t->data2 > max) max = t->data2;
findData2Max (t->left, max);
findData2Max (t->right,max);
}
}