input: Write a Python function to reverse a linked list.
  assert linked_list_to_list(reverse_linked_list(create_linked_list([1, 2, 3, 4, 5]))) == [5, 4, 3, 2, 1]
  assert linked_list_to_list(reverse_linked_list(create_linked_list([10, 20, 30, 40]))) == [40, 30, 20, 10]
  assert linked_list_to_list(reverse_linked_list(create_linked_list([7, 14, 21]))) == [21, 14, 7]
output: class ListNode:
      def __init__(self, val=0, next=None):
          self.val = val
          self.next = next
  
  def reverse_linked_list(head):
      prev = None
      current = head
      while current:
          next_node = current.next
          current.next = prev
          prev = current
          current = next_node
      return prev
  
  def create_linked_list(elements):
      if not elements:
          return None
      head = ListNode(elements[0])
      current = head
      for element in elements[1:]:
          current.next = ListNode(element)
          current = current.next
      return head
  
  def linked_list_to_list(head):
      elements = []
      current = head
      while current:
          elements.append(current.val)
          current = current.next
      return elements