Insertion Sort in Linked Lists

I tried doing this question using a doubly linked list . Also I only changed the order of the int data stored in the nodes and didn’t change the ordering of the nodes. Is it the correct approach?
code link: https://ide.codingblocks.com/s/45246

Hey Kshitij, the approach of changing the order of the int data stored in the nodes and not changing the ordering of the nodes is practically it would work but when you are told to perform insertion sort in a linked list you are supposed to change the nodes pointers instead of swapping the data of nodes.

Understood. Can it be done using a singly linked list instead of a doubly?

Yes it can be done but for singly linked list you have to use an another linked list.

Thanks a lot for the help

No problem keep coding and raising doubts :slight_smile: