First of ALL
- Both are 100 % same, Same meaning Same Working
- Developer have just used 2 If Statements(first one to show a message that it is not found)
and 2nd One to Return Back, While he can do both in 1 If as well, Maybe he just wanted to
show that he knows both approaches that's why he did it that way Else there is no
difference in Both and that it might have taken one more BIG O time.
-For More clear view you can Visit this link
(difference between p == NULL and !p in c++)
DETAILED ANSWER IS BELOW:
!p and p==nullptr both have the same Working
The code in your case shows, that if(!p) and if(p==nullptr) both are used just to show, that the Developer know's Both Approaches and he is a senior developer familiar with older versions of C++
Because if he uses
if(!p){throw out_of_range("The key you're looking for can't be found\n");
return;
}
or Uses
if(p==nullptr)
{throw out_of_range("The key you're looking for can't be found\n");
return;}
But in Your case the Only Thing developer did he
Showed the Message that Node not found in First IF
And returned the Function in Second If.No matter whatever was in his mind or his intentions were to Do, But Both are Same and its just use of Another IF which is not Needed at All
If you still Required more help about the Detailed Difference Between Both you can check at difference between p == NULL and !p in c++
pin the code is a reference to a pointer. Does this make a difference?ifin the code snippet?