Слияние кода завершено, страница обновится автоматически
/***************************************************************************
> File Name : LinkedList.js
> Author : zhoutk
> Mail : zhoutk@189.cn
> Create Time : 2015-09-18 10:23
***************************************************************************/
(function(){
"use strict";
var Node = require("./lib/SingleNode");
function LinkedList(){
this._head = new Node("This is Head Node.");
this._size = 0;
}
LinkedList.prototype.isEmpty = function(){
return this._size === 0;
};
LinkedList.prototype.size = function(){
return this._size;
};
LinkedList.prototype.getHead = function(){
return this._head;
};
LinkedList.prototype.display = function(){
var currNode = this.getHead().next;
while(currNode){
console.log(currNode.element);
currNode = currNode.next;
}
};
LinkedList.prototype.remove = function(item){
if(item) {
var preNode = this.findPre(item);
if(preNode == null)
return ;
if (preNode.next !== null) {
preNode.next = preNode.next.next;
this._size--;
}
}
};
LinkedList.prototype.add = function(item){
this.insert(item);
};
LinkedList.prototype.insert = function(newElement, item){
var newNode = new Node(newElement);
var finder = item ? this.find(item) : null;
if(!finder){
var last = this.findLast();
last.next = newNode;
}
else{
newNode.next = finder.next;
finder.next = newNode;
}
this._size++;
};
/*********************** Utility Functions ********************************/
LinkedList.prototype.findLast = function(){
var currNode = this.getHead();
while(currNode.next){
currNode = currNode.next;
}
return currNode;
};
LinkedList.prototype.findPre = function(item){
var currNode = this.getHead();
while(currNode.next !== null && currNode.next.element !== item){
currNode = currNode.next;
}
return currNode;
};
LinkedList.prototype.find = function(item){
if(item == null)
return null;
var currNode = this.getHead();
while(currNode && currNode.element !== item){
currNode = currNode.next;
}
return currNode;
};
module.exports = LinkedList;
})();
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )