I am trying to learn to implement DSs in C++ and here is a simple implementation. Please review in terms of optimization, memory management, coding standards, etc
#include <stdio.h>
#include <iostream>
class BstNode{
int data;
BstNode* left;
BstNode* right;
public:
BstNode(int data)
{
this->data = data;
this->left = NULL;
this->right = NULL;
}
~BstNode();
void Insert(int data)
{
if(this->data >= data)
{
if (this->left == NULL)
this->left = new BstNode(data);
else
this->left->Insert(data);
}
else
{
if (this->right == NULL)
this->right = new BstNode(data);
else
this->right->Insert(data);
}
}
bool Search(int data)
{
if(this->data == data)
return true;
else if(this->data >= data)
{
if(this->left == NULL)
return false;
else
return this->left->Search(data);
}
else
{
if(this->right == NULL)
return false;
else
return this->right->Search(data);
}
}
};
int main()
{
BstNode* ptr_root = new BstNode(15);
ptr_root->Insert(10);
ptr_root->Insert(16);
int num;
std::cout<<"Enter the number: \n";
std::cin>> num;
if (ptr_root->Search(num))
std::cout<<"Found\n";
else
std::cout<<"Not Found\n";
return 0;
}
'BstNode::Search': not all control paths return a value
. \$\endgroup\$