+ 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
1 Resposta
+ 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