0% found this document useful (0 votes)
13 views2 pages

Exercitii Arbori Binari de Cautare

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Exercitii Arbori Binari de Cautare

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

function isBTS(node*node)

begin
if node ==null
return true
if (node->left!=null && maxValue(node->left) > node->value)
return false;

if (node->right!=null && minValue(node->right) < node>value)


return false;

if (!isBST(node->left) || !isBST(node->right))
return false;
return true;
end
---------------------------------------------------------------------

function MinVal(node*node)
begin

if (node*node==null && node->left == null)


return node->value
else
return MinVal(node->left)
end

---------------------------------------------------------------------

function inorder(v,visit)
begin
if (v==null) then
return false
else
inorder(v->stg,visit)
visit(v)
if (v->value>=a && v->value<=b && !visit(node->value))
return node->value
inorder(v->drp,visit)
end
--------------------------------------------------------

Procedure height(Node *root)


{
if( root == nullptr )
return -1;
else
return 1 + max(height(root->left),height(root->right));
}
--------------------------------------------------------

Procedure isAVL(Node *root)


{
if(root == nullptr)
return true;
else if (abs(height(root->left) - height(root->right)) <= 1 )
return isAVL(root->left) and isAVL(root->right);
else
return false;
}
-------------------------------------------------------------
Sort(v,n)
Li=1
Ls=n
Function binarytree(li,ls,v)
Begin
If(li>ls)
Return NULL
else
Mij=(li+ls)/2
Nod->value=v[mij]
Nod->left=binarytree(li,mij-1,v)
Nod->right=binarytree(mij+1,ls,v)
Return Nod
End
--------------------------------------------------------------

Function greaterSum(Node* root, &sum = 0)


{
if(root == nullptr)
return;
greaterSum(root->right, sum);
sum += root->value;
root->value = sum - root->value;
greaterSum(root->left,sum);
}

You might also like