I am starting to learn binary trees in cpp and dynamically allocated memories; thus to initialize a struct I do this
struct node{
int val;
node* left;
node* right;
};
//Initialize:
node* root = new node;
root->val = 7;
root->left = NULL;
root->right = NULL;
I would like to know if there is a better way to set the struct values without writing the last three lines of code. I saw on some web pages that they do this:
int* n = new int(6);
Thanks!