input: Write a python function to reverse a linked list.
  assert reverse([1, 2, 3, 4, 5]).to_list() == [5, 4, 3, 2, 1]
  assert reverse([10, 20, 30]).to_list() == [30, 20, 10]
  assert reverse([1]).to_list() == [1]
output: class ListNode:
      def __init__(self, value=0, next=None):
          self.value = value
          self.next = next
  
      def to_list(self):
          result = []
          current = self
          while current:
              result.append(current.value)
              current = current.next
          return result
  
  def reverse(head):
      prev = None
      current = head
  
      while current:
          next_node = current.next
          current.next = prev
          prev = current
          current = next_node
  
      return prev
  
  def build_linked_list(values):
      if not values:
          return None
      head = ListNode(values[0])
      current = head
      for value in values[1:]:
          current.next = ListNode(value)
          current = current.next
      return head
  
  # Helper function to convert a list to a linked list and back for testing
  def reverse_list(values):
      head = build_linked_list(values)
      reversed_head = reverse(head)
      return reversed_head.to_list()