A JavaScript linked list

xiaoxiao2021-03-05  20

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 ()

{

THISHEAD = 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;