编辑代码

// 链表和数组区别优缺点
// 链表在空间上不连续 不用创建时声明空间大小
// 数组插入元素要移动元素,消耗比较大
// 链表方向是单一的 需要从一头到另一头实现

class Node {
    constructor(element, next = undefined) {
        this.element = element;
        this.next = next;
    }
}

class LinkedList {
    constructor() {
        this.head = null;
        this.length = 0;
    }

    push(element) {
        const node = new Node(element);
        if (this.head == null) {
            this.head = node;
        } else {
            current = this.head;
            while(current.next != null) {
                current = current.next
            }
            current.next = element;
        }
        this.length++;
    }

    insert(element, position) {
        const node = new Node(element);
        if (this.head == null) {
            this.head = node;
        } else {

        }
    }

    getElementAt() {

    }

    remove() {

    }

    indexOf() {

    }

    removeAt() {

    }

    isEmpty() {
        return this.length === 0? true : false;
    }

    
}

// 双向链表 循环链表