doubleLink = function(){
this.head = null;
this.feild = null;
this.size= 0;
this.head = {};
//return a empty double link list
this.head.next = this.head;
this.head.before = this.head;
};
doubleLink.prototype.isBefore = function(a, b){
//is a before b?
var listItem = a;
while (listItem != b) {
listItem = listItem.next;
if (listItem == this.head) {
return false;
}
}
return true;
};
doubleLink.prototype.insert = function(/*Object*/item,/*Object*/ targetItem,/*Boolen*/ before){
if (!targetItem) {
var listItem = this.head.next;
if (listItem == this.head) {
//insert first node
this.head.next = item;
this.head.before = item;
item.before = this.head;
item.next = this.head;
}
else {
//insert node at the last position
listItem = this.head.before;
listItem.next = item;
item.before = listItem;
this.head.before = item;
item.next = this.head;
}
}
else {
if (!before) {
//insert after targetItem
item.next = targetItem.next;
item.next.before = item;
targetItem.next = item;
item.before = targetItem;
}
else {
//insert before targetItem
item.before = targetItem.before;
item.before.next = item;
targetItem.before = item;
item.next = targetItem;
}
}
this.size++;
};
doubleLink.prototype.remove = function(/*Object*/item){
item.before.next = item.next;
item.next.before = item.before;
item.next = null;
item.before = null;
this.size--;
};
doubleLink.prototype.removeAll = function(){
var listItem = this.head.next;
while (listItem != this.head) {
listItem.before = null;
listItem = listItem.next;
listItem.before.next = null;
}
listItem.before.next=null;
this.head.next=this.head;
this.head.before=this.head;
this.size = 0;
};
doubleLink.prototype.size = function(){
return this.size;
};
doubleLink.prototype.showAll = function(){
//just for test.
var position = 0;
var str = '';
var listItem = this.head.next;
while (listItem != null) {
str += position + ':' + listItem.node.id + ';';
listItem = listItem.next;
position++;
}
console.info('show all:' + str);
};
//test double linklist
function start(){
var ss0={};
var ss1={};
var ss2={};
var ss3={};
var list = new doubleLink();
list.insert(ss0);
list.insert(ss2);
list.insert(ss3);
list.insert(ss1);
console.info(list.isBefore(ss3,ss1));
} Smilar Posts of JavaScript's Double Link List
-
Buffalo has PHPRPC and those differences
zhou7707 wrote Asked about Comet support on how to? 陈金洲of Buffalo and has those differences? 1, PHPRPC with Buffalo positioning different, Buffalo only positioning in a Javascript to Java's remote ...
-
IE and Firefox (Firefox) in the JavaScript area is not compatible and unified method summarized
IE and Firefox (Firefox) in the JavaScript area is not compatible and unified method summarized
-
Play flash page 3 (javascript script swfobject.js1)
/ ** * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/ * * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License: * Http://www.opensource.or ...
-
Read "prototype.js 1.4 Developer Edition Manual" excerpt
Information Address: http://thinhunan.cnblogs.com/archive/2006/04/01/DeveloperNotesForPrototype.html Extract 1, $ F () function Function: Return of any form input control value, the parameters are the ...
-
Javascript object inheritance
Javascript object inheritance
-
Msxml2.XMLHTTP version problem
Projects with an import feature prototype.js of Ajax functionality to update the prompt, the code is very simple, do not have the framework of the background on a jsp to output Text, future use of tim ...
-
JS after ajax request return of the problem can not be implemented
1: Send ajax request, in the onComplete, if back when the html contains a javascript, then these javascrip and will not be realized, it does not mean not to implement. This problem has troubled me for ...
-
Javascript Object Model
Javascript Object Model
-
JS in the Date type conversion
http://blog.csdn.net/yzy0612/archive/2007/08/07/1730732.aspx
-
JavaScript inheritance
About JavaScript inherited a small example ... demo4







