Lorsque j'appelle la fonction createBst(), le programme se termine dans la fonction.
J'ai placé une instruction d'impression après la fonction, mais elle n'est pas appelée, ni l'instruction d'impression suivante "terminated".
int main(){
bst b;
b.createBst();
std::cout<<"terminated"<<std::endl;
return 0;
}
class node{
public:
int val;
node* left;
node* right;
};
class bst{
public:
node* head;
void createBst();
node* newNode(int val);
};
node* bst::newNode(int v){
node n1;
node* n=&n1;
n->val=v;
n->left=nullptr;
n->right=nullptr;
return n;
}
void bst::createBst(){
head=bst::newNode(10);
head->left=bst::newNode(11);
(head->left)->left=bst::newNode(7);
head->right=bst::newNode(9);
(head->right)->left=bst::newNode(15);
(head->right)->right=bst::newNode(8);
}
la sortie doit être "terminée".