js实现简单的单链表,后续实现链表的删除功能 1. [代码] [JavaScript]代码 function Entry(next, data){ this.next = next; this.data = data;}function List(){ this.head=new Entry(null,null); this.end=new Entry(null,null); th
1. [代码][JavaScript]代码
function Entry(next, data)
{
this.next = next;
this.data = data;
}
function List()
{
this.head=new Entry(null,null);
this.end=new Entry(null,null);
this.add=function(data)
{
var newentry=new Entry(null,data);
if(this.head.data)
{
this.end.next=newentry;
this.end=newentry;
}
else
{
this.head=newentry;
this.end=newentry;
}
};
this.show=function()
{
var temp=this.head;
for(;temp!=null;temp=temp.next)
{
alert(temp.data);
}
};
}
var a=new List();
a.add(1);
a.add(2);
a.add(3);
a.show();
