代码拉取完成,页面将自动刷新
/***************************************************************************
> File Name : DoubleLinkedList.js
> Author : zhoutk
> Mail : [email protected]
> Create Time : 2015-09-25 12:05
***************************************************************************/
(function(){
"use strict";
var Node = require("./lib/DoubleNode");
function DoubleLinkedList(){
this._head = new Node("This is Head Node.");
this._size = 0;
}
DoubleLinkedList.prototype.getHead = function(){
return this._head;
};
DoubleLinkedList.prototype.isEmpty = function(){
return this._size === 0;
};
DoubleLinkedList.prototype.size = function(){
return this._size;
};
DoubleLinkedList.prototype.findLast = function(){
var currNode = this.getHead();
while(currNode.next){
currNode = currNode.next;
}
return currNode;
};
DoubleLinkedList.prototype.add = function(item){
if(item == null)
return null;
this.insert(item);
};
DoubleLinkedList.prototype.remove = function(item){
if(item) {
var node = this.find(item);
if(node == null)
return ;
if (node.next === null) {
node.previous.next = null;
node.previous = null;
} else{
node.previous.next = node.next;
node.next.previous = node.previous;
node.next = null;
node.previous = null;
}
this._size--;
}
};
DoubleLinkedList.prototype.find = function(item){
if(item == null)
return null;
var currNode = this.getHead();
while(currNode && currNode.element !== item){
currNode = currNode.next;
}
return currNode;
};
DoubleLinkedList.prototype.insert = function(newElement, item){
var newNode = new Node(newElement);
var finder = item ? this.find(item) : null;
if(!finder){
var last = this.findLast();
newNode.previous = last;
last.next = newNode;
}
else{
newNode.next = finder.next;
newNode.previous = finder;
finder.next.previous = newNode;
finder.next = newNode;
}
this._size++;
};
DoubleLinkedList.prototype.dispReverse = function(){
var currNode = this.findLast();
while(currNode != this.getHead()){
console.log(currNode.element);
currNode = currNode.previous;
}
};
DoubleLinkedList.prototype.display = function(){
var currNode = this.getHead().next;
while(currNode){
console.log(currNode.element);
currNode = currNode.next;
}
};
module.exports = DoubleLinkedList;
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。