本文整理汇总了C++中tree::comp方法的典型用法代码示例。如果您正苦于以下问题:C++ tree::comp方法的具体用法?C++ tree::comp怎么用?C++ tree::comp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::comp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Delete_Element
node Delete_Element(tree t, node Parent, void * data, int *H, int * found, void * found_data)
{
node Temp;
if(!Parent)
{
printf("\n datarmation does not exist");
return(Parent);
}
else
{
if (t->comp(data, Parent->data) < 0)
{
Parent->left = Delete_Element(t, Parent->left, data, H, found, found_data);
if(*H)
Parent = Balance_Right_Heavy(Parent, H);
}
else if(t->comp(data, Parent->data) > 0)
{
Parent->right = Delete_Element(t, Parent->right, data, H, found, found_data);
if(*H)
Parent = Balance_Left_Heavy(Parent, H);
}
else
{
*found = 1;
*((int*)found_data) = (int) Parent->data;
Temp= Parent;
if(Temp->right == NULL)
{
Parent = Temp->left;
*H = T;
free(Temp);
}
else if(Temp->left == NULL)
{
Parent = Temp->right;
*H = T;
free(Temp);
}
else
{
Temp->left = DELETE(Temp->left, Temp, H);
if(*H)
Parent = Balance_Right_Heavy(Parent, H);
}
}
}
return(Parent);
}
示例2: tree_compare
int tree_compare(tree t1, tree t2) {
if (t1->comp != t2->comp) return 1;
if (t1->size != t2->size) return 1;
list values1 = tree_to_list(t1);
list values2 = tree_to_list(t2);
int len = t1->size;
int i = 0;
for (i = 0; i < len; ++i) {
void * p1 = list_get(values1, i);
void * p2 = list_get(values2, i);
if (t1->comp(p1,p2) != 0) {
return 1;
}
}
list_free(values1);
list_free(values2);
return 0;
}
示例3: Binary_Tree
node Binary_Tree(tree t, void * data, node Parent, int *H, int * found)
{
node Node1;
node Node2;
if(!Parent)
{
Parent = (node) malloc(sizeof(struct node));
Parent->data = data;
Parent->left = NULL;
Parent->right = NULL;
Parent->flag = 0;
*H = T;
return (Parent);
}
if(t->comp(data, Parent->data) < 0)
{
Parent->left = Binary_Tree(t, data, Parent->left, H, found);
if(*H)
/* Left branch has grown higher */
{
switch(Parent->flag)
{
case 1: /* Right heavy */
Parent->flag = 0;
*H = F;
break;
case 0: /* Balanced tree */
Parent->flag = -1;
break;
case -1: /* Left heavy */
Node1 = Parent->left;
if(Node1->flag == -1)
{
Parent->left= Node1->right;
Node1->right = Parent;
Parent->flag = 0;
Parent = Node1;
}
else
{
Node2 = Node1->right;
Node1->right = Node2->left;
Node2->left = Node1;
Parent->left = Node2->right;
Node2->right = Parent;
if(Node2->flag == -1)
Parent->flag = 1;
else
Parent->flag = 0;
if(Node2->flag == 1)
Node1->flag = -1;
else
Node1->flag = 0;
Parent = Node2;
}
Parent->flag = 0;
*H = F;
}
}
}
else if(t->comp(data, Parent->data) > 0)
{
Parent->right = Binary_Tree(t,data, Parent->right, H, found);
if(*H)
/* Right branch has grown higher */
{
switch(Parent->flag)
{
case -1: /* Left heavy */
Parent->flag = 0;
*H = F;
break;
case 0: /* Balanced tree */
Parent->flag = 1;
break;
case 1: /* Right heavy */
Node1 = Parent->right;
if(Node1->flag == 1)
{
Parent->right= Node1->left;
Node1->left = Parent;
Parent->flag = 0;
Parent = Node1;
}
else
{
Node2 = Node1->left;
Node1->left = Node2->right;
Node2->right = Node1;
Parent->right = Node2->left;
Node2->left = Parent;
if(Node2->flag == 1)
Parent->flag = -1;
else
Parent->flag = 0;
if(Node2->flag == -1)
//.........这里部分代码省略.........