hello dear i was debugging the following code it was giving following error
234 D:\Documents and Settings\Administrator\My Documents\Untitled1.cpp expected constructor, destructor, or type conversion before '*' token 234 D:\Documents and Settings\Administrator\My Documents\Untitled1.cpp expected `,' or `;' before '*' token [/b]
newbalf(n->parent);
temp=findimbal(n->parent);//temp var is pointing to imbal node
if(temp==NULL)
return ;
else
rotation(temp);
}
}
void tree::rotation(node *r)
{ node* A,*B,*C,*F;
A=r;
F=r->parent;
if(r->b==2)
{//left sub tree has more node
B=A->left;
if(r->left->b==+1)
{//left-left rotation
C=B->left;
A->left=B->right;
B->right=A;
if(F==NULL)
{//Root is changed
p=B;
cout<<"root is changed\n";
}
else
{
if(F->right==A)
F->right=B;
else
F->left=B;
B->parent=F;
A->parent=B;
A->left->parent=A;
}
//call update balance fator form A as B is parent
newbalf(A);
//end of left-left rotation
}
else//left right rotation
{
C=B->right;
A->left=C->right;
C->right->parent=A;
B->right=C->left;
C->left->parent=B;
C->left=B;
B->parent=C;
C->right=A;
A->parent=C;
C->parent=F;
if(F==NULL)
{
p=C;
cout<<"root is changed\n";
}
else
{
if(F->right=A)
F->right=C;
else
F->left=C;
}
newbalf(A);
newbalf(B);
//end of lr rotation
}
}//end of all left rotation
else
{//right child has more node
B=A->right;
if(r->b==-1)
{
C=B->right;
A->right=B->left;
A->right->parent=A;
B->left=A;
A->parent=B;
B->parent=F;
if(F==NULL)
{
p=B;
cout<<"root node changed\n";
}
else
{
if(F->right==A)
F->right=B;
else
F->left=B;
}
newbalf(A);
//end of right rotation
}
else
{
C=B->left;
B->left=C->right;
B->left->parent=B;
A->right=C->left;
A->right->parent=A;
C->right=B;
B->parent=C;
C->left=A;
A->parent=C;
C->parent=F;
if(F==NULL)
{
p=C;
cout<<"root changed\n";
}
else
{
if(F->right=A)
F->right=C;
else
F->left=C;
}
newbalf(A);
newbalf(B);
//end of right-left rotation
}
//end of right rotation
}
//end of function rotation
}
void tree:: newbalf(node* r)
{ //traversing back to root and filling new balance factor
while(r!=p)
{
r->b=height(r->left)-height(r->right);
r=r->parent;
}
}
node* tree :: findimbal(node *r)
{ // find node whose balfactor is -2
while(r!=p)
{
if((r->b==-2)||r->b==2)
return r;
else
r=r->parent;
}
//reached root thus tree bal
cout<<"tree is balance after insertion\n";
return NULL;
}
void tree::inorder(node *q)
{
if(q!=NULL)
{
inorder(q->left); //By recurssion
cout<<"\t "<<q->data<<flush;
inorder(q->right);//By recurssion
}