I'm trying to implement a character BST. I can't wrap my head around the logic of inserting characters. So let's say this is in main insert("a"); insert("b"); insert("c"); insert("d"); When will the a letter ever be less than a ? So would my tree basically be all on the right side ?
a
\
b
\
c
\
d
Like that ? Since there wouldn't ever be a letter that is less than a. But this feels wrong, but I'm not sure what I'm missing.
My insert function:
void insert(char letter, node * curr)
{
int count{0};
if ( strcmp(curr->getLetter(), letter) == 0)
return 0;
if (!curr->getRight() && strcmp(curr->getLetter(), letter) > 0)
{
curr->getRight() = new node(letter);
return 1;
}
if (!curr->getLeft() && strcmp(curr->getLetter(), letter) < 0)
{
curr->getLeft() = new node(letter);
return 1;
}
if (strcmp(letter, curr->getLetter() ) < 0)
count += insert(letter, curr->getLeft() );
else
count += insert(letter, curr->getRight() );
return count;
}