a general version of merging two sorted linkedlist