This looks almost exactly like the merge sort algorithm. Merge sort - Wikipedia, the free encyclopedia

The main part you need is the merge function. It takes 2 lists that are in sorted order (from...