I need to merge two doubly-linked lists, but not by their values (the lists are not sorted). I want to obtain a single list that has all the nodes from the two, but in the order in which they appear in memory.
Maybe this image helps more: http://img140.imageshack.us/i/drawing2.png/
Is there any algorithm (preferably a fast one) that can do this kind of merge ? Maybe this is a bit helpful:
- the start node of the lists is always before the other ones.
- a list can have up to 8192 nodes.
- I know where the nodes are located in memory because the lists keep track of free location in a big block of memory (used in a memory allocator).
- I work in C++.
Thanks in advance!