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 4055636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:43:34+00:00 2026-05-20T14:43:34+00:00

Since black red tree is a binary search tree I have decided to use

  • 0

Since black red tree is a binary search tree I have decided to use inheritance for implementation. Here is how in short node inheritance looks in my code:

struct BST_node
{
   // public interface here

   int key;
   BST_node* left;
   BST_node* right;
   BST_node* parent;
};

struct BRT_node : BST_node
{
   // public interface here

   NodeColour colour;
};

Problem I have encountered with this is pointers in derived class are type of the base class. Therefore I cannot use them in context of derived class without explicit casting. Maybe hiding members and using virtual accesor methods could do the trick, but that would destroy this simple syntax:

node->left = node->parent;

Is there a better way of doing this?

  • 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-05-20T14:43:34+00:00Added an answer on May 20, 2026 at 2:43 pm

    What’s wrong with putting all the data members in BRT_node?

    struct BRT_node
    {
        int key;
        BRT_node* next;
        BRT_node* prev;
        BRT_node* parent;
        NodeColour colour;
    };
    

    This way, you get to keep the “nice syntax” of node->left = node->parent;.

    The problem with using inheritance here is because the red-black tree algorithms require BRT_nodes, not BST_nodes. So inheritance in this case isn’t appropriate.

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

Sidebar

Related Questions

Since Java uses a red-black tree to implement the TreeMap class, is the efficiency
Since C++ STL set/map are implemented as red-black trees, it should be possible to
I have a problem with the rb-trees. according to wikipedia, rb-tree needs to follow
Since drawing fonts is quite expensive in terms of CPU, many developers use a
I was testing this, since I understood using XHTML let me use any valid
I have a following requirement for a very complex UI. (Complex here means there
I'm going to post my code first since it is short and easy to
In my iOS 5 app I have a custom UIButton that has a red
I have this jquery snippet. Since it is not passing me the value, I
Magento Orders->Google Sitemap ... since recently a blank page?!!!! Hi since some weeks our

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.