Insert Data function

Why we are using cin two times in build data function to take the input from the user .

Hi @StreamerX

As the input format is such that the input is terminated by -1. Hence we first take input of data outside of while loop. If it enters the loop, then it means that first value was not equal to -1 and so we insert it at tail. Then again take input for next node while checking data!=-1.

Hope it Helps.

@StreamerX
Please mark your doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.