im trying to run this code that adds a name and displays it. i keep getting the same message. can anyone tell me what i have done wrong?
thank you.
#include <iostream>
#include <string>
using namespace std;
class treenode
{
public:
string data;
treenode * left;
treenode * right;
// Constructor. Make a node containing "student".
treenode(string student)
{
data = student;
left = NULL;
right = NULL;
}
};
class MyBST
{
private:
treenode * root;
public:
MyBST();
//Insert item s into a tree rooted at r
void add(treenode * & r, string student);
//Display all items in the tree in order (in-order traversal)
void printAlpha(treenode * r);
};
//constructor
MyBST::MyBST()
{
root = NULL;
}
//function to add
void add(treenode * & r, string s)
{
if( r == NULL ) //empty tree, easy case!!!!!!
{
//create a new node, point r at it
r = new treenode(s);
}
else if( s > r->data ) //go right!
{
add( r->right, s );
}
else // go left
{
add( r->left, s);
}
}
//function to print in alphabetical order
void printAlpha(treenode * r)
{
if( r != NULL )
{
printAlpha(r->left); //print items in left subree
cout << r->data << endl; //print item at root
printAlpha(r->right); //print items in right subtree
}
}
//////////////
//main program
//////////////
int main()
{
MyBST firsttry;
firsttry.add("name");
firsttry.display();
while(true){}
return 0;
}