it says cannot convert string to char please help, it needs to be string. c++ i will include the source main and .h classes //bt.cpp - file contains member functions #include "bt.h" #include using namespace std; //Constructor BT::BT() { root = NULL; } //Insert new item in BST void BT::insert(string d) { node* t = new node; node* parent; t->data = d; //THE ERROR MESSAGE IS FROM HERE t->left = NULL; t->right = NULL; parent = NULL; if (isEmpty()) root = t; else { //Note: ALL insertions are as leaf nodes node* curr; curr = root; // Find the Node's parent while (curr) { parent = curr; if (t->data > curr->data) curr = curr->right; else curr = curr->left; } if (t->data < parent->data) parent->left = t; else parent->right = t; } } ___________________________________________________________________________________________ #include "bt.h" #include #include using namespace std; int main() { BT b; int ch, num; string d; cout << "-----------Menu-------------" << endl; cout << endl; cout << "1. Insert node(s)" << endl; cout << "2. Traverse Preorder" << endl; cout << "3. Traverse Inorder" << endl; cout << "4. Traverse Inorde" << endl; cout << "5. Quit" << endl << endl; do { cout << endl << "Enter Your Choice <1 - 5> "; cin >> ch; switch (ch) { case 1: cout << "Enter number of nodes to insert: "; cin >> num; for (int i = 0; i> d; //b.insert(toupper(d)); cout << "Inserted." << endl; } ____________________________________________________________________________________________ //bt.h - header file contains the object description #include #ifndef BT_H #define BT_H using namespace std; class BT { private: struct node { char data; //whatever is the data type; use that node* left; node* right; }; node* root; public: BT(); //Constructor bool isEmpty() const { return root == NULL; } //Check for empty void insert(string); //Insert item in BST }
it says cannot convert string to char please help, it needs to be string. c++ i will include the source main and .h classes
//bt.cpp - file contains member functions
#include "bt.h"
#include <iostream>
using namespace std;
//Constructor
BT::BT()
{
root = NULL;
}
//Insert new item in BST
void BT::insert(string d)
{
node* t = new node;
node* parent;
t->data = d; //THE ERROR MESSAGE IS FROM HERE
t->left = NULL;
t->right = NULL;
parent = NULL;
if (isEmpty())
root = t;
else
{
//Note: ALL insertions are as leaf nodes
node* curr;
curr = root;
// Find the Node's parent
while (curr)
{
parent = curr;
if (t->data > curr->data)
curr = curr->right;
else
curr = curr->left;
}
if (t->data < parent->data)
parent->left = t;
else
parent->right = t;
}
}
___________________________________________________________________________________________
#include "bt.h"
#include<string>
#include <iostream>
using namespace std;
int main()
{
BT b;
int ch, num;
string d;
cout << "-----------Menu-------------" << endl;
cout << endl;
cout << "1. Insert node(s)" << endl;
cout << "2. Traverse Preorder" << endl;
cout << "3. Traverse Inorder" << endl;
cout << "4. Traverse Inorde" << endl;
cout << "5. Quit" << endl << endl;
do
{
cout << endl << "Enter Your Choice <1 - 5> ";
cin >> ch;
switch (ch)
{
case 1:
cout << "Enter number of nodes to insert: ";
cin >> num;
for (int i = 0; i<num; i++)
{
cout << endl;
cout << "Enter node: ";
cin >> d;
//b.insert(toupper(d));
cout << "Inserted." << endl;
}
____________________________________________________________________________________________
//bt.h - header file contains the object description
#include <iostream>
#ifndef BT_H
#define BT_H
using namespace std;
class BT
{
private:
struct node
{
char data; //whatever is the data type; use that
node* left;
node* right;
};
node* root;
public:
BT(); //Constructor
bool isEmpty() const { return root == NULL; } //Check for empty
void insert(string); //Insert item in BST
}
Step by step
Solved in 2 steps