Just using pseudocode to understand the process:
bCount = the number of entries in B
aCount = the number of entries in A minus 1 (i.e. minus the last entry which the process always leaves as is, so the last one is ignored)
aLastEntry = the last entry
Result will be the final list
LoopRangeEnd = aCount
<!-- this is the main process -->
Loop, setting nIndex from 1 to LoopRangeEnd (in steps of 1)
If item nIndex from A exists in B
Then add item nIndex from A to Result
Otherwise
If nIndex > bCount
Then add the last item from A to Result
Otherwise
Then add item nIndex from B to result
<-- after the main process, tack on the last entry from A -->
Finally, add the last item from A to result
Let me know if that makes sense. If it does, I think I can do that.