from structures import ListNode

def to_linked(values):
    dummy = ListNode()
    tail = dummy
    for value in values:
        tail.next = ListNode(value)
        tail = tail.next
    return dummy.next

def to_values(head):
    output = []
    current = head
    while current is not None:
        output.append(current.val)
        current = current.next
    return output
