一个Javascript链表
发表于:2007-05-25来源:作者:点击数:
标签:
function Entry(next, data) { this.next = next this.data = data } function Iterator(node) { this.cousor = node this.hasNext = function () { return (this.cousor.next != null); } this.next = function () { var rt = this.cousor.next this.cousor
function Entry(next, data)
{
this.next = next
this.data = data
}
function Iterator(node)
{
this.cousor = node
this.hasNext = function ()
{
return (this.cousor.next != null);
}
this.next = function ()
{
var rt = this.cousor.next
this.cousor = this.cousor.next
return rt.data
}
}
function LinkedList()
{
this.head = new Entry(null, null)
this.size = function ()
{
var size = 0
if (this.head == null)
{
return size
}
var p = this.head.next
for(; p!=null; p = p.next)
size++;
return size;
}
this.clear = function ()
{
this.head = null
}
this.getNode = function (idx)
{
var pos = -1;
原文转自:http://www.ltesting.net
|