특징

장점과 단점

예시 코드

class ListNode {
    constructor(value) {
        this.value = value;
        this.next = null;
    }
}

function addNode(head, value) {
    if (!head) return new ListNode(value);

    let current = head;
    while (current.next !== null) {
        current = current.next;
    }
    current.next = new ListNode(value);
    return head;
}

function printList(head) {
    let current = head;
    let values = [];
    while (current) {
        values.push(current.value);
        current = current.next;
    }
    console.log(values.join(" "));
}

let head = new ListNode(1);
head = addNode(head, 3);
head = addNode(head, 5);
printList(head);