Insert sort doubt

what is wrong in the code
last node in result is unexpected

if nodes are less it works fine
but when i entered 15-16 nodes then 1 element gets placed at wrong position

21 12 42 21 -2412 421 4 21 421 5 51 23 5634 2 35 25 23 523 2 -1

try this input

Hello @yatin,

Run your code for the following inputs:

Example1:
21 12 42 21 -2412 421 4 21 421 5 51 23 5634 -1 2 35 25 23 523 2

Example2:
21 12 42 21 -2412 -1 421 4 21 421 5 51 23 5634 2 35 25 23 523 2

I hope, you must have found the reason for the missing value.
This is happening because of the way you are taking input for linked list.
operator overloded function is considering -1 as EOF.
Thus, it is not taking any element after -1.

BTW, you can test your code here:
https://hack.codingblocks.com/contests/c/93/545
NOTE: Change the input and output format before submitting your code.
If you still have doubts, feel free to ask

Hope, this would help.
Give a like, if you are satisfied.

but sir there i have not used -1 anywhere in between then why is it givings such output

what is the reason of 523 at the end in the output

I am sorry,
I interpreted your doubt wrongly.

It’s not the length that is causing any issue.
Your program is running correctly for the test case of same length as one you have provided:
21 12 42 21 -2412 421 4 21 421 5 51 23 5634 2 35 25 23 3 2 -1

Your Test case is:
21 12 42 21 -2412 421 4 21 421 5 51 23 5634 2 35 25 23 523 2 -1
Your Output is:
-2412->2->2->4->5->12->21->21->21->23->23->25->35->42->51->421->421->5634->523->

If you observe the position of 523 is second last but it is present at last index.
It is because of the logical error in the SortedInsert() function.
while(temp->next!=NULL)
This loop is iterating till the node prior to the last node.
Which means it is not running for last node.
But, to place 523 at it’s correct location it is necessary to compare the data with the last node.

I have modified this function, now it’s working correctly.

Hope, this would help.
Give a like, if you are satisfied.