Linked list using insertion sort


error,compilation mistake?

@Vibhuti0206 you are using “sort” as a name of your function, which the compiler is mistaking with the STL algorithm::sort function.
Try to use unique names for your custom functions, such as mysort(), etc.

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.

https://ide.codingblocks.com/s/189424,still giving errors?

@Vibhuti0206,
“qsort” is also a inbuilt C++ STL function. Please use unique names like mySort etc.
And also you need to declare a function before using it.

I have tried again,it is giving no output…kindly check https://ide.codingblocks.com/s/189424

@Vibhuti0206,
Return type of your build function is node* so you need to update the head pointer in main with this returned value,
try this:

head = build(head, data);

https://ide.codingblocks.com/s/201991,still not working

Hi @Vibhuti0206 when working with linked lists, it is always better to point the pointers elsewhere, instead of creating a whole new list. Right now the list only has integers, but what if you were working with a node which had lots of data? copying all that data multiple times would increase both space and time complexity.

In this program, you haven’t stored the new value of head2 that you returned in your sort program at multiple places. I have made changes to your code here. https://ide.codingblocks.com/s/202181
Please mark your doubt as resolved if you are satisfied.

still giving run error

@Vibhuti0206 that might be because you are not checking for head2->next->data without checking if head2->next exists at that point or not

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.