Sort linked list using insertion sort

I have solved this question perfectly. I am in doubt whether this is the correct approach for this question. My code is https://ide.codingblocks.com/s/202846

@adarsh_anand
hello adarsh,
the merge algorithm u r using is applicable only if u have given two sorted list.

so ur approach will work only when given list is already sorted

Sir,
Prev points to the head of my sorted part and one by one I am passing current to merge function which returns prev as the head and so on. That’s why my code passed all the test cases.

@adarsh_anand
ok so ur current is pointing to single node right?
and prev is head of sorted list. and then u are merging this prev list with that single node right ?

if this was ur logic then fine. i thought u are merging unsorted list

yes sir this is my logic. I just wanted to ask whether this is the correct implementation of insertion sort?

@adarsh_anand
yeah it correct

1 Like