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
}
}
查看全文
相关阅读:
方差分析 | ANOVA | 原理 | R代码 | 进阶 | one way and two way | Analysis of Variance
GT sport真实赛道详解
如何成为F1车手?
统计学 | 漫想
(转)什么是P问题、NP问题和NPC问题
一个完整的成年果蝇大脑的电子显微镜图谱 | A Complete Electron Microscopy Volume of the Brain of Adult Drosophila melanogaster
文献导读 | A Pan-Cancer Analysis of Enhancer Expression in Nearly 9000 Patient Samples
综述
GSEA
(转)决定系数R2
原文地址:https://www.cnblogs.com/jacktu/p/1011505.html
最新文章
通过android studio的gradle强制cmake输出命令详情
ubuntu 使用dpkg手动安装deb包时发生循环依赖的解决办法
GDB查看堆栈局部变量
java 和 c++ 实现的各种基础数据结构和算法
移动端安卓IOS对接H5项目遇到的坑
Ajax返回值一直获取不到啊
怎么解析后台返回数据中 换行
Js 事件委托 解决动态元素不能click点击的问题
VScode 编辑器快捷键被占用
Jquery 如何设置多个attr()属性
热门文章
遇到报错 Error on descrypt request code
小米MIUI配色
提升固态硬盘性能
TP5.1 模板不解析
GT sport赛道详解
多重线性回归 (multiple linear regression) | 变量选择 | 最佳模型 | 基本假设的诊断方法 | multiple testing
regression | p-value | Simple (bivariate) linear model | 线性回归 | 多重检验 | FDR | BH | R代码
F1赛道
GT sport赛道详解
final model for life | digital life
Copyright © 2011-2022 走看看