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
}
}
查看全文
相关阅读:
__getitem__ 方法的使用
python加载测试用例时,修改用例不必须以“test”开头
python 反射
python 类中__getattr__的使用
python 中 __dict__函数的使用
python 类中__int__和__str__的使用
ubuntu16.04Nvidia驱动、CUDA、cuDNN安装与卸载
C++中的各种可调用对象
ubuntu16.04安装QGIS工具
C/C++中extern关键字详解
原文地址:https://www.cnblogs.com/jacktu/p/1011505.html
最新文章
用 Lua 实现一个微型虚拟机-基本篇
介绍一个非常好用的跨平台C++开源框架:openFrameworks
在 OpenGL ES 2.0 上实现视差贴图(Parallax Mapping)
从零开始写一个武侠冒险游戏-8-用GPU提升性能(3)
从零开始写一个武侠冒险游戏-7-用GPU提升性能(2)
翻译:非常详细易懂的法线贴图(Normal Mapping)
从零开始写一个武侠冒险游戏-6-用GPU提升性能(1)
aarch执行stream
aarch执行spec2006
AttributeError: 'unicode' object has no attribute 'tzinfo' 未解决
热门文章
linux创建用户并锁定用户目录和首次登陆强制修改密码
django简单密码加密和效验
mesos-slave启动不起来
zookeeper的java问题
子网掩码转换
代码这样写更优雅,15篇 Python 技术热文
python文件夹遍历,文件操作,获取文件修改创建时间
django 连接mysql数据库
python 发送带附件邮件
namedtuple的使用方法
Copyright © 2011-2022 走看看