// Node 类
function Node(element) {
this.element = element; //当前节点的元素
this.next = null; // 下一个节点链接
}
// LinkedList 类
function LList() {
this.head = new Node('head'); // 头节点
this.find = find;
this.insert = insert;
this.remove = remove;
this.findPrev = findPrev;
this.display = display;
}
// 实现查找节点的方法
function find(item) {
let currNode = this.head;
while (currNode.element !== item) {
currNode = currNode.next;
}
return currNode;
}
function insert(newElement, item ) {
let newNode = new Node(newELement);
let currNode = this.find(item);
newNode.next = currNode.next;
currNode.next = newNode;
}
var fruits = new LList();
fruits.insert = ('Apple', 'head');
console.log('fruits', fruits);
console