Question

In: Computer Science

C++ Please write a exmaple of class template RedBlackTree.h.(It must be template!). I do not mind...

C++ Please write a exmaple of

class template RedBlackTree.h.(It must be template!).

I do not mind about details but please include the basic functions that are necessary for a RedBlackTree.

Solutions

Expert Solution

As per the question we have to write template for RedBlackTree.h file.

As before writing it, let’s understand what is template firstly;

So as per the programming of generic code where we write code which is depend upon some particular type where it can be blue-print of code/program and even formula also.

Let’s see Syntax:

template <class type> return type function-name (parameter list)

{

. .

. .

. .

}

As per this example we have write template for RedBlackTree. As per the question we have freedom to have any class & method to have so for easy understandings let’s take class named

RedBlackTree and another one as RedBlackNode.

Where,

RedBlackTree is going to be container class for this example. And where we can have methods like:-

1. Insert

2. Search

3. Delete

As well as for traversal,

1. First

2. Last

3. Append

And other friend class will be Node of this tree.

For creating tree In this example we have to allocate instance of RedBlackTree().

As this class is defined as temple class it will have method like insert and traversal methods.

Let’s understand template of RedBlackTree class:

template<class key>

Class RedBlackTree {

Public:

  RedBlackTree();

// this will help to specify methods like insert and delete

RedBlackTree( int (*(com_val) (key ,key&));

//this will help to specify fuctions like append/delete

RedBlackTree(void (*del_val) (key &val));

//this will help to do both oprations

~ RedBlackTree();

//Destructor

//methods tobe implemented:

void insert (key, &val);

void delete ();

void search ();

.

.

.

//Traversal methods

void first();

void last();

void append();

.

.

.

};

So as we defining template key can be of any type it will work.

As we can also add Marcos for traversal like this:-

#define RedBlackTree_traversal (tree)

{   .

  .

    . }

#define RedBlackTree_ReverseTravarsal (tree)

{ .

    .

    . }

As per above we have written a template for RedBlackTree.


Related Solutions

please do this in C++! I want to understand it, it must be done before the...
please do this in C++! I want to understand it, it must be done before the evening or nightime. Follow instructions exactly as it says. Please send a screenshot also with your code so I can see how it is supposed to be formatted. Since typing it a chegg answer, makes it look a bit messy. Your program will read in a file of commands. There are three types of commands: Warrior creates a new warrior with the specified name...
Write a template class Number with the following features Overload following operators for the template class...
Write a template class Number with the following features Overload following operators for the template class + - < > Overload << and >> operators for the ostream and istream against this class. Write a main function to demonstrate the functionality of each operator.
Write a template class Number with the following features Overload following operators for the template class...
Write a template class Number with the following features Overload following operators for the template class + - < > Overload << and >> operators for the ostream and istream against this class. Write a main function to demonstrate the functionality of each operator.
A header file contains a class template, and in that class there is a C++ string...
A header file contains a class template, and in that class there is a C++ string object. Group of answer choices(Pick one) 1)There should be a #include for the string library AND a using namespace std; in the header file. 2)There should be a #include for the string library. 3)There should be a #include for the string library AND a using namespace std; in the main program's CPP file, written before the H file's include.
Please write in C++ as simple as possible I want you to create a Book Class...
Please write in C++ as simple as possible I want you to create a Book Class for a bookstore. I am not going to tell you what variables should go into it, that is for you to figure out (but you should have at least 5+). And then you must create a UML with all the variables and methods (like: the getters and setters, a default constructor, and a constructor that takes all the variables and finally the printValues() )....
Do it in python please! also please use this template please I have provided and below...
Do it in python please! also please use this template please I have provided and below is the activity def main(): # import the module random try: # asking the user to enter a number between 1 and 100 #loop time while if elif #for loop # generates that number of random integers and stores them in a list for x in # computations # displays the results on the screen # call try_Again to give the user the opportunity...
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template....
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template. And rewrite your main function to test your template for integer array and double array. Following is my complete code: #include <iostream> using namespace std; class Array { private: // Pointer to memory block to store integers int* data; // Maximum size of memory block int cap; // Stores number of integers in an array int num; public: // Constructor Array(int size); // Default...
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
I need to write a resume and I do not know how to write it. Please...
I need to write a resume and I do not know how to write it. Please help me. My name is John Doe. I finished Associate of Science in (Electrical Engineering, Computer Engineering, Physics and Math) from Community College. I have work experience over 10 years at food company. Please help me write as completely as possible. Thanks a lot for your help!
I have to do a nursing skill template in a few sentences can you please describe...
I have to do a nursing skill template in a few sentences can you please describe the nursing interventions for trach suctioning (pre,intra,post). and the outcome and evaluations of trach suctioning
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT