Please help the code compiles but then gives runtime error and I have no Idea why please help with the insert of the book
the .h file
#ifndef BOOK_H
#define BOOK_H
#include <string>
#include "Person.h"
using namespace std;
struct node
{
node *left;
node *right;
Person data;
};
class Book
{
public:
Book();
virtual ~Book();
void insert(Person contact);
node *search(string name);
void removeContact(string name);
protected:
private:
node *root;
node *current;
};
#endif // BOOK_H
the actual code
#include <string>
#include "Book.h"
using namespace std;
Book::Book()
{
root = NULL;
}
Book::~Book()
{
}
void Book::insert(Person contact)
{
string name = contact.getName();
int number = contact.getNumber();
if(root == NULL)
{
root->data = Person(name, number);
cout << "\nroot\n";
root->left = NULL;
root->right = NULL;
current = root;
}
else if(contact.getName() < current->data.getName())
{
if(current->left == NULL)
{
current->left->data = contact;
current = root;
cout << "\nleft\n";
}
else
{
current = current->left;
insert(contact);
}
}
else if(contact.getName() >= current->data.getName())
{
if(current->right == NULL)
{
current->right->data = contact;
current = root;
}
else
{
current = current->right;
insert(contact);
}
}
}