functionfind(element) { var current = this.head; while(current.element != element){ current = current.next; } return current; }
插入新节点
1 2 3 4 5 6
functioninsert(newElement, currentItem) { var current = this.find(currentItem); var newNode = new Node(newElement); newNode.next = current.next; current.next = newNode; }
得到某一节点的前一节点
1 2 3 4 5 6 7 8
functionfindPrevious(element){ var current = this.head; while((current.next.element != element) && (current.next != null)) { current = current.next; } return current; }