Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bst::recInsert(string s, node * & r)
- {
- if( r == NULL ) //base case: empty tree
- {
- r = new node;
- r->data = s;
- r->height = 0;
- }
- else if( s < r->data ) //insert left
- {
- recInsert(s, r->left);
- if( height(r->left) - height(r->right) > 1 )
- { //violation!
- //do some type of rotation
- else if( s < r->left->data )
- leftRotation(r);
- else //its a double
- doubleRotationLeft(r);
- if(s>r->data)
- }
- r->height = max( height(r->left), height(r->right) ) +1;
- }
- else//insert right, if greater or equal to root
- {
- recInsert(s, r->right);
- if( height(r->right) - height(r->left) > 1 )
- {
- if( s > r->right->data )
- rightRotation(r);
- else
- doubleRotationRight(r);
- }
- r->height = max( height(r->left), height(r->right) ) +1;
- }
- }
Add Comment
Please, Sign In to add comment