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
}
}
查看全文
相关阅读:
php wamp 配置虚拟主机
php xml 操作。
第一个输入框中 输入 test,第二个输入框中自动出现 test.baibu.com
正则表达式 手机号码的验证
JQery 设置 退格键 不可用 jQery 中的keydown 事件
YII 片段缓存如何实现。
php set_time_limit() 函数
VLAN
进程
802.11无线网络权威指南
原文地址:https://www.cnblogs.com/jacktu/p/1011505.html
最新文章
Django框架(十九)—— drf:序列化组件(serializer)
C语言——指针
Django框架(十八)—— CBV源码分析、restful规范、restframework框架
Django框架(十七)—— 中间件、CSRF跨站请求伪造
Django框架(十八)—— auth框架:用户登录、注册、认证
Django框架(十六)—— cookie和session组件
Django框架(十五)—— forms组件、局部钩子、全局钩子
java web 404错误页面配置
could not resolve property
layer 如何加上关闭框
热门文章
有时候错误很奇怪啊,Comparator问题
net.sf.json.JSONException: There is a cycle in the hierarchy!
为什么需要两次eval才转化为需要的JSON数据,好奇怪
Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnl
数据库物理文件隐藏了,需要显示出来
word里搜狗输入法出不来,可以按ctrl+空格键
Hibernate 批量update数据时,怎么样做可以回滚,
css 集锦。
Yii 如何渲染另一控制器中的视图。
用例图的作用 如何画用例图
Copyright © 2011-2022 走看看