双向链表:(插入,增加,删除)
function Node(element) {
this.node = element;
this.next = null;
this.front = null;
}
function insert(position,head,element) {
var cur = head;
for(let i=0; i<position; i++) {
cur = cur.next;
}
var newNode = new Node(element);
var NEXT = cur.next;
newNode.front = cur;
cur.next = newNode;
if(NEXT) {
newNode.next = NEXT;
NEXT.front = newNode;
}
}
function deletenode(position,head) {
var cur = head;
for(let i =0; i<position; i++) {
cur = cur.next;
}
var FRONT = cur.front;
cur.front.next = cur.next;
if(cur.next) {
cur.next.front = FRONT;
}
}
function add(head,element) {
var position=0;
var cur = head;
while(cur) {
cur = cur.next;
position++;
}
insert(position-1,head,element);
}
var head = new Node('1');
insert(0,head,'2');
add(head,'3')
deletenode(1,head)
console.log(head)