Insertion Sort with Linked Lists

This is a discussion on Insertion Sort with Linked Lists within the C++ Programming forums, part of the General Programming Boards category; The code I have isn't right, and I know it. However, I've spent a few hours on this and don't ...

One way to solve the problem is to break it down into smaller chunks.
For example, this code takes an unsortedList, empties that out, and places all the items in sorted order into sortedList. In other words, it performs a full insertion sort, but requires you to code the functions that are missing.

Code:

while (!unsortedList.empty())
sortedList.insert(unsortedList.pop_front());

And of course afterwards you can just swap the sorted and unsorted list contents to get it all back into the original list.

So you now have three smaller sub-problems to solve: empty, insert, and pop_front. Whether you're doing a singly-linked or doubly-linked list, this will simplify things for you to the point where you might be able to solve it on your own I expect.