Hi all I'm so close to getting this stupid binary tree to work except I keep getting some wack ass error message. It says
and I quote error C2440: '=' : cannot convert from 'char' to 'char12]'
observe the code
Code:
#include <iostream>
#include <string>
using namespace std;
struct node
{
char info[12];
node *left;
node *right;
};
//The line below should be in main and you should probably
//not be allocating memory for a new node at this point,
//that will be done in the insert function, you
//should just set it to NULL in main
// Forgot to add the return types for the two functions below
void preorder(node *p);
void inorder(node *p); //is this the correct syntax for declaring the function?
void insert(node *&p, char string[12]); //for user defined functions using pointers?
void insert(node *&p, char string[12]) // This differs from the function prototype you provided above
{
if(p==NULL)
{
p=new(node);
p->info = string[12];
p->left=NULL;
p->right=NULL;
}
else if(string < p->info)
{
insert(p->left, string);
}
else insert(p->right, string);
} // You were missing an ending bracket, add this
void inorder(node *p)
{
if(p!=NULL)
{
inorder(p->left);
cout<<p->info<<" ";
inorder(p->right);
}
}
void preorder(node *p)
{
if(p!=NULL)
{
cout<<p->info<<" ";
preorder( p->left);
preorder(p->right);
}
}
int main() // main should always return an int
{
node *root=NULL;
char string[12];
for(int i=0; i<6; ++i)
{
cout<<"Enter the value for your node: ";
cin.getline(string, 11, '\n');
insert(root, string[12]); // Your insert function takes two parameters but you only provide one
}
inorder(root);
cout<<endl;
preorder(root);
return 0;
}
anyhow could anyone out there give me some feedback on where I'm going wrong here.