0

this is what compiler shows
tree.cpp: In member function ‘void redblacktree<T>::insert(T) [with T = int]’:
tree.cpp:187:12: instantiated from here
tree.cpp:103:9: error: lvalue required as left operand of assignment
tree.cpp:140:9: error: lvalue required as left operand of assignment

if u don't want 2 go thru' d code then kindly just tell when such compilation error occur.

#include<iostream>
using namespace std;

template <class T>
class redblacktree {
public:
T x;
redblacktree<T> *left, *right, *parent;
int leftsize; // number of nodes in left subtree
int r; // the number of black nodes on any path
// from the current node to a leaf in its subtree
bool color;
redblacktree<T> *root;


redblacktree():root(NULL){}
void insert(T y)
{
 cout<<"root->x=";
 redblacktree<T> *p,*q;
 if(root==NULL)
 {
  q=new redblacktree<T>;
  q->x=y;
  q->left=q->right=q->parent=NULL;
  q->leftsize=0;
  q->r=1;
  q->color=false;
  root=q;
  cout<<"root->x="<<root->x<<endl; 
 }

 else
 {
  p=root;
  q=new redblacktree<T>;
   q->x=y;
   q->left=q->right=NULL;
   q->leftsize=0;
   q->r=0;
   q->color=true; 
 cout<<"fuk u"<<endl;
  while((p->right!=NULL)&&(p->left!=NULL))
  {
   if(y>p->x)
    p=p->right;
   
   else if(y<p->x)
    p=p->left;
  }
  
   if(y>p->x)
    {
    p->right=q;
    q->parent=p;
    }
   else if(y<p->x)
    {
    p->left=q;
    q->parent=p;
     cout<<"fuk u"<<endl;
    
    while((q->parent!=NULL)&&(q->parent->left==q))
    {
     q->parent->leftsize+=1;
     q=q->parent;
     }
     q=p->left;
    }
  
   if((q->parent!=NULL)&&(q->parent->parent!=NULL))
   {
      redblacktree<T> *pu,*gu;
      pu=q->parent;
      gu=q->parent->parent;   
    while((q->parent->color=true)&&(q->color=true))
    {
     if((q->parent->parent->right==NULL)||(q->parent->parent->right->color==false))
     {
      
      if(q->parent->parent->left->left==q)
      {
       if(gu->parent->left==gu)
        gu->parent->left=pu;
       else
        gu->parent->right=pu;
       pu->parent=gu->parent;
       gu->left=pu->right;
       pu->right->parent=gu;
       pu->right=gu;
       gu->parent=pu;
       pu->color=false;
       gu->color=true;
      }  
      else
      {
       if(gu->parent->left==gu)
        gu->parent->left=q;
       else
        gu->parent->right=q;
       q->parent=gu->parent;
       if(q->left!=NULL) 
        q-left->parent=pu;
       if(q->right!=NULL)
        q->right->parent=gu;
       gu->left=q->right;
       pu->right=q->left;
       q->left=pu;
       q->right=gu;
       pu->parent=q;
       gu->parent=q;
       q->color=false;
       gu->color=true;
      }
     }
     else if((q->parent->parent->left==NULL)||(q->parent->parent->left->color==false))
     {
      if(q->parent->parent->right->right==q)          
      {
       if(gu->parent->left==gu)
        gu->parent->left=pu;
       else
        gu->parent->right=pu;
       pu->parent=gu->parent;
       gu->right=pu->left;
       pu->left->parent=gu;
       pu->left=gu;
       gu->parent=pu;
       pu->color=false;
       gu->color=true;
      } 
      else
      {
       if(gu->parent->left==gu)
        gu->parent->left=q;
       else
        gu->parent->left=q;
       q->parent=gu->parent;
       if(q->left!=NULL) 
        q-left->parent=gu;
       if(q->right!=NULL)
        q->right->parent=pu;
       gu->right=q->left;
       pu->left=q->right;
       q->right=pu;
       q->left=gu;
       pu->parent=q;
       gu->parent=q;
       q->color=false;
       gu->color=true;
      }
     } 
     else if(q->parent->parent->right->color==true)
     {
      q->parent->color=false;
      q->parent->parent->right->color=false;
      if(q->parent->parent!=root)
      {
       q->parent->parent->color=true;
       q=q->parent->parent; 
      }
      else
       break;
     }
     else if(q->parent->parent->left->color==true)
     {
      q->parent->color=false;
      q->parent->parent->left->color=false;
      if(q->parent->parent!=root)
       {
       q->parent->parent->color=true;
       q=q->parent->parent; 
       }
      else
       break;
     }    
    }
   }   
 
 }
}
};

int main()
{
redblacktree<int> rb;
rb.insert(1);
rb.insert(0);
rb.insert(45);
rb.insert(-34);
rb.insert(60);
rb.insert(12);
rb.insert(9);
cout<<rb.root->leftsize<<endl;
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Narue
0

Typo: q-left->parent=pu; should be q->left->parent=pu; . In an annoyance you'll encounter many times, the symmetric case has the same problem in the same place because you probably cut and pasted to get it.

Another line that raises red flags is this one:

while((q->parent->color=true)&&(q->color=true)) {

Did you intend to use assignment?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.