Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:24:19+00:00 2026-06-15T19:24:19+00:00

I am implementing a Red-Black tree in c++, but I am having trouble with

  • 0

I am implementing a Red-Black tree in c++, but I am having trouble with my rotation methods. The insert method works just fine without any balancing, but as soon as I try to rotate, my tree loses information. My guess is that I’m not setting pointers to the nodes in the right way, but I don’t quite understand exactly what is going wrong here.

Here is my rotate right method:

void RedBlackTree::rotateRight(RedBlackNode *localRoot) {
cout << "rotateRight - local root " << localRoot->data << endl;
RedBlackNode *temp = localRoot->left;
localRoot->left = temp->right;
temp->right = localRoot;
localRoot = temp;
}

An example of what is happening is I insert c, b, and a. The tree initially looks like this:

    c
   /
  b
 /
a

After the rotation, the tree will only print out the root node, c.

Any ideas on what may be going on? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:24:20+00:00Added an answer on June 15, 2026 at 7:24 pm

    It’s hard to tell based on the code segment but localRoot is a local pointer whose change is forgotten the moment you leave the function. If you want to get it changed in the context where the function is being called from, you either want to pass it as RedBlackNode*& or you should return the value as result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been implementing my own version of a red-black tree, mostly basing my algorithms
I'm implementing a red/black tree in Java and to verify if my tree is
I'm currently implementing a red-black tree data structure to perform some optimizations for an
i just started implementing redis with node. during an implementation of authentication method i
I have two themes on my site: Red, and Blue. This works fine. I
In my iPhone app I am implementing Audio Recording, It works on iPhone simulator/Device
I was looking for a tree or graph data structure in C#, but I
Busy implementing Twitter Bootstrap with the responsive CSS file included, but this causes issues
I am stumped at this step while implementing a ternary tree: #include<stdio.h> #include<string.h> #include<stdlib.h>
Edit: Hmm this is interested. I just noticed, my signup route is /signup. But,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.