input: Write a function to merge two sorted lists A and B into a single sorted list. The function should take the first element of list A and compare it with the first element of list B. If the element of A is greater, it should add the element of B to the result list and move the pointer of B to the next element. If the element of A is smaller, it should move the pointer of A to the next element and repeat the comparison. The function should continue this process until all elements from both lists are added to the result list. If one list is exhausted before the other, the function should append the remaining elements of the non-exhausted list to the result list.
  
  
  def merge_sort(A, B):
      result = []
      i, j = 0, 0
  
      # Compare elements and add lower one to result
      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
  
      # Add remaining elements
      result += A[i:]
      result += B[j:]
  
      return result
  
  # Test the algorithm
  A = [3, 6, 8, 10, 11]
  B = [2, 5, 7, 12]
  
  print(merge_sort(A, B))  # Output: [2, 3, 5, 6, 7, 8, 10, 11, 12]
  
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