In an online event, I have to complete a partially finished code. They use linklist data structure to store each element.The time complexity is O(n*n) And in the outer (for) loop, the iteration is completed when node->next!= NULL (i.e. only n-1 checks). Inner (for) loop, there are n checks until (ptr becomes NULL)
say, there are 5 elements. And, Elements in given order 5 ->3 ->1 ->2 ->4 ->NULL
Sort Cycles:
1 ->3 ->5 ->2 ->4 ->NULL
1 ->2 ->5 ->3 ->4 ->NULL
1 ->2 ->3 ->5 ->4 ->NULL
1 ->2 ->3 ->4 ->5 ->NULL
Elements in sorted order
1 ->2 ->3 ->4 ->5 ->NULL
Which sorting algorithm is used here?