#include <iostream>
#include <functional>
using namespace Std;
Template <class t>
Class Tree
{
Private
struct Node
{
T data;
node* L;
node* R;
Node (T D):d Ata (d), L (null), R (null) {}
};
node* Root;
int Count;
Public
Tree (): Root (NULL), Count (0) {}
tree& Insert (T D)
{
function<tree& (Node*&, t&) > INS = [&] (node*& R, t& DD)->tree&
{
if (r = = NULL)
{
R = new Node (DD);
return *this;
}
else if (DD < r->data)
{
return ins (r->l, DD);
}
Else
{
return ins (R->r, DD);
}
};
count++;
return ins (root, D);
}
void Travel ()
{
Function<void (node*&) > tra = [&] (node*& R)
{
if (r = = NULL)
{
Return
}
TRA (r->l);
cout << r->data << "";
TRA (r->r);
};
TRA (root);
}
node*& Find (T D)
{
function<node*& (node*&, t) > FID = [&] (node*& R, t dd)->node*&
{
if (r = = NULL)
{
return R;
}
else if (R->data = = dd)
{
return R;
}
else if (R->data < DD)
{
Return FID (R->R, DD);
}
Else
{
Return FID (R->L, DD);
}
};
return FID (root, D);
}
BOOL If_empty ()
{
return root = = NULL;
}
BOOL Remove (T D)
{
Function<bool (node*, t) > REM = [&] (node* R, t DD)
{
node*& temp = Find (dd);
if (temp = = NULL)
{
return false;
}
node* p = temp;
if (temp->l)
{
There's no right subtree, no need to think about it.
node* pn = temp;
while (PN->R)
{
PN = pn->r;
}
Pn->r = temp->l;
}
temp = temp->r;
Delete p;
p = NULL;
return true;
};
return REM (root, D);
}
void Updata (T D)
{
Insert (d);
}
void Clear ()
{
Function<void (node*&) > CLS = [&] (node*& R)
{
if (r = = NULL)
{
Return
}
CLS (R->L);
CLS (R->R);
Delete R;
R = NULL;
};
CLS (root);
}
int High ()
{
Function<int (node*) > h = [&] (node* R)
{
if (r = = NULL)
{
return 0;
}
int lh = h (r->l);
int RH = h (r->r);
Return 1 + (LH > RH LH:RH);
};
return h (Root);
}
};
int main ()
{
Tree<int> T;
Cin.get ();
return 0;
}
Using wrappers and lambda expressions to implement a two-fork lookup tree