I have a project that is due Monday night. The project is to implement a Red Black Tree that reads in the declaration of Independence as "Independence.txt" and puts those strings into a red black tree. I am trying to implement it as a Binary Search Tree first and then will add the colors and the rotations as I already have that code worked out.
The problem I am facing is that right now I keep getting the following errors: "error C2660" 'RBT ::Insert': function does not take 1 arguments" and "IntelliSense: non suitable conversion function from "std:string" to "RBT::RBTNode *" exists" and then IntelliSense: too few arguments in function call which points to the line root.Insert(myString);
I also need help with reading in the file into the binary search tree. I do think my insert method is correct, and the problem lies in the main method.
Thanks for any help as I am stuck.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
template<typename T>
class RBT
{
struct RBTNode {
T data;
RBTNode* left;
RBTNode* right;
};
public:
RBT();
~RBT();
void GetNewNode(RBTNode* root, T data);
void Insert(RBTNode* root, T data);
bool Search();
void Display();
};
template <typename T>
void RBT<T>::GetNewNode(RBTNode* root, T data) {
RBTNode* newNode = new RBTNode();
newNode->data = data;
newNode->left = newNode->right = NULL;
return newNode;
}
template <typename T>
void RBT<T>::Insert(RBTNode* root, T data) {
if (root == NULL) {
root = GetNewNode(data);
}
else if (data <= root->data) {
root->left = Insert(root->left, data);
}
else {
root->right = Insert(root->right, data);
}
return root;
}
template<typename T>
bool RBT<T>::Search() {
if (root == NULL) return false;
else if (root->data == data) return true;
else if (data <= root->data) return Search(root->left, data);
else return Search(root->right, data);
}
template<typename T>
void RBT<T>::Display() {
if (root->left != NULL)
display(root->left);
cout << root->left << endl;
if (root->right != NULL)
Display(root->right);
cout << root->right << endl;
}
int main()
{
RBT<string> root;
string myString;
ifstream infile;
infile.open("Independence.txt");
while (infile)
{
infile >> myString;
root.Insert(myString);
}
cin.ignore();
return 0;
}