input: Write a function to merge two sorted lists A and B into a single sorted list by comparing the first elements of both lists. If the first element of A is smaller, append it to the result list and move the pointer of A to the next element. If the first element of B is smaller, append it to the result list and move the pointer of B to the next element. Continue this process until all elements from both lists are added to the result list. If either list runs out of elements before the other, append the remaining elements from the non-empty list to the result list. Return the merged sorted list. If either list is empty, return the non-empty list as the result.
  def merge_sort(A, B):
   result = []
   i, j = 0, 0
  
   while i < len(A) and j < len(B):
    if A[i] < B[j]:
     result.append(A[i])
     i += 1
    else:
     result.append(B[j])
     j += 1
  
   result += A[i:]
   result += B[j:]
  
   return result
  
  #Test the algorithm
  assert merge_sort([3, 6, 8, 10, 11], [2, 5, 7, 12]) == [2, 3, 5, 6, 7, 8, 10, 11, 12]
  assert merge_sort([], [2, 5, 7, 12]) == [2, 5, 7, 12]
  assert merge_sort([3, 6, 8, 10, 11], []) == [3, 6, 8, 10, 11]
  assert merge_sort([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
  assert merge_sort([], []) == []
output: def merge_sort(A, B):
   result = []
   i, j = 0, 0
  
   while i < len(A) and j < len(B):
    if A[i] < B[j]:
     result.append(A[i])
     i += 1
    else:
     result.append(B[j])
     j += 1
  
   result += A[i:]
   result += B[j:]
  
   return result