title: Convert Binary Tree to doubly linked list. How can I avoid using global variable here?
body: <p>The convert function converts the binary tree to linked list. I couldn't pass test cases in geeksforgeek because of using global variable. How can I avoid using a global variable?</p>
  <pre><code> prev = None
   head = None
  
  def convert(root):
      global prev
      global head
      if root is None:
          return 
  
      convert(root.left)
      if head== None:
          head = root
          prev = root
      else:
          root.left = prev
          prev.right = root
      prev = root
      convert(root.right)
  </code></pre>