+ 2

Difference ?

Global root Node* root = NULL; Now What is the difference between below 2 snippets for above global root node pointer _____________________________ int key = 8; Node p(key); root = &p; _____________________________ Node* p = new Node(key); root = p; ---------------------- Method 2 is working fine , but 1 is not https://code.sololearn.com/cli95tT47la9/?ref=app

2nd Dec 2021, 1:37 PM
saurabh
saurabh - avatar
1 Odpowiedź
+ 1
1 is not working because Node p will no longer exist once you return from BST::Insert 2 instead creates a new Node that will exist until you delete it
9th Dec 2021, 12:50 PM
Angelo
Angelo - avatar