// Basic singly linked list of Int64 values.
class Node {
    public let value: Int64
    public var next: Node?
}

class LinkedList {
    var head: Node?

    fn prepend(value: Int64) {
        head = Node(value: value, next: head)
    }

    fn append(value: Int64) {
        let node = Node(value: value, next: null)
        if head == null {
            head = node
            return
        }
        var cursor = head
        while cursor.next != null {
            cursor = cursor.next
        }
        cursor.next = node
    }

    fn len() {
        var count = 0
        var cursor = head
        while cursor != null {
            count = count + 1
            cursor = cursor.next
        }
        return count
    }
}

let numbers = LinkedList(head: null)
numbers.append(20)
numbers.prepend(10)
numbers.append(30)
print(numbers.len()) // 3
