zoukankan
html css js c++ java
javascript中实现的链表
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
;
var
p
=
this
.head
while
(p
!=
null
&&
pos
<
idx)
{
p
=
p.next;
pos
++
;
}
return
p;
}
this
.get
=
function
(idx)
{
return
this
.getNode(idx).data
}
this
.add
=
function
(data)
{
this
.insert(
this
.size(), data)
}
this
.insert
=
function
(idx, data)
{
var
p
=
this
.getNode(idx
-
1
);
/**/
/*
注意查询idx-1
*/
if
(p
==
null
)
{
return
}
var
node
=
new
Entry(p.next, data)
p.next
=
node
}
this
.remove
=
function
(idx)
{
var
prenode
=
this
.getNode(idx
-
1
)
var
node
=
this
.getNode(idx)
if
(prenode
==
null
||
node
==
null
)
{
return
null
}
prenode.next
=
node.next
return
node.data
}
this
.iterator
=
function
()
{
return
new
Iterator(
this
.head)
}
this
.swap
=
function
(a, b)
{
var
av
=
this
.getNode(a)
var
bv
=
this
.getNode(b)
var
tmp
=
av.data
av.data
=
bv.data
bv.data
=
tmp
}
}
查看全文
相关阅读:
C#获取网上图片的宽高代码
发现两个有趣的CSS3效果
.NET WinForm画树叶小程序
生产环境使用 pt-table-checksum 检查MySQL数据一致性【转】
awk入门【转】
MySQL数据库之auto_increment【转】
crontab的使用方法
linux添加swap分区【转】
nginx反向代理转发后页面上的js css文件无法加载【原创】
Serv-U日志文件保存设置【转】
原文地址:https://www.cnblogs.com/jacktu/p/1011505.html
最新文章
spring 多数据源一致性事务方案
Elasticsearch、Logstash、Kibana搭建统一日志分析平台
大数据实践-数据同步篇tungsten-relicator(mysql->mongo)
网贷之家的爬虫之旅
jq倾斜的动画导航菜单
jQuery的eq方法
博客园计划今天相当霸气
HTML5锚点请用id代替name
js获取页面中图片的总数
jQ获取浏览器window的高宽
热门文章
css中white-space的值pre-wrap
jQuery鼠标经过显示大图
Silverlight的TextWrapping
Visual Studio添加dll程序集引用操作步骤
从博客园网站分类引发的猜测
jQuery弹出关闭遮罩层
SilverLight MD5加密
用html5的canvas画布绘制贝塞尔曲线
jquery只能输入数字方法
C#在图片上添加文字代码
Copyright © 2011-2022 走看看