js链表操作
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function Node(v){
this.value=v;
this.next=null;
}
function ArrayList(){
this.head=new Node(null);
this.tail = this.head;
this.append=function(v){
node = new Node(v);
this.tail.next=node;
this.tail=node;
}
this.insertAt=function(ii,v){
node = new Node(v);
//找到位置的节点
tempNode=this.head;
for(i=0;i<ii;i++){
if(tempNode.next!=null){
tempNode=tempNode.next;
}else{
break;
}
}
node.next=tempNode.next;
tempNode.next = node;
}
this.removeAt=function(ii){
node1=this.head; //要删除节点的前一个节点
for(i=0;i<ii;i++){
if(node1.next!=null){
node1=node1.next;
}else{
break;
}
}
node2=node1.next; //要删除的节点
if(node2!=null){
node1.next = node2.next;
if(node2.next==null){
this.tail=node1;
}
}
} }
function Iterator(arryList){
this.point=arryList.head;
this.hasNext=function(){
if(this.point.next!=null){
this.point=this.point.next;
return true;
}else{
return false;
}
}
this.next=function(){
return this.point.value;
}
} var arry = new ArrayList();
arry.append(1);
arry.append(2);
arry.append(3);
arry.insertAt(1,8);
arry.insertAt(0,9);
arry.insertAt(100,100);
arry.insertAt(1000,1000);
arry.insertAt(1,200);
arry.insertAt(200,2000); iterator = new Iterator(arry);
while(iterator.hasNext()){
document.write(iterator.next());
document.write('<br/>');
}
</script>
</head>
<body> </body>
</html>
js链表操作的更多相关文章
- js简单操作Cookie
贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...
- JAVA 链表操作:循环链表
主要分析示例: 一.循环链表简述 二.单链表循环链表 三.双链表循环链表 一.循环链表简述 循环链表即链表形成了一个循环的结构,尾节点不再指向NULL,而是指向头节点HEAD,此时判定链表的结束是尾节 ...
- 单链表操作B 分类: 链表 2015-06-07 12:42 15人阅读 评论(0) 收藏
数据结构上机测试2-2:单链表操作B TimeLimit: 1000ms Memory limit: 65536K 题目描述 按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除 ...
- YTU 2620: B 链表操作
2620: B 链表操作 时间限制: 1 Sec 内存限制: 128 MB 提交: 418 解决: 261 题目描述 (1)编写一个函数createlink,用来建立一个动态链表(链表中的节点个数 ...
- 使用HTML5的JS选择器操作页面中的元素
文件命名为:querySelector.html,可在Chrome浏览器中预览效果. 1 <!DOCTYPE html> 2 <html lang="en"> ...
- C# 链表操作
关于链表操作,在C#当中微软已经提供了一个LinkedList<T>的数据结构,通过这个类提供的一系列方法就能够实现链表操作. 这里我提供一段代码,这是在论坛里面有人提问时给出的代码,它实 ...
- C语言,单链表操作(增删改查)(version 0.1)
这天要面试,提前把链表操作重新写了一遍.备份一下,以备不时之需. 希望有人能看到这篇代码,并指正. // File Name : list.h #include "stdafx.h" ...
- node.js高效操作mongodb
node.js高效操作mongodb Mongoose库简而言之就是在node环境中操作MongoDB数据库的一种便捷的封装,一种对象模型工具,类似ORM,Mongoose将数据库中的数据转换为Jav ...
- C语言链表操作模板(添加,删除,遍历,排序)
C语言链表操作模板,摘自郝斌的C语言视频教程,简单的修改成了纯C格式.当年照着视频学习的时候记录下来的,在使用的时候直接拿来修改修改修改能节约不少时间的. /********************* ...
随机推荐
- 图片加载ImageLoader
https://github.com/nostra13/Android-Universal-Image-Loader public class AtguiguApplication extends A ...
- static_func
<?php function testing() { static $a = 1; $a *= 2; echo $a."\n"; } testing(); testing() ...
- 继承、多态——成员变量、成员函数、构造函数(this、super)
继承 1.继承使用原因: 1.提高了代码的复用性 2.让类与类之间产生了关系,有了这个关系,才有了多态的特性 2.继承注意事项: 千万不要为了获取其他类的功能,简化代码而继承. 必须是类与类之间有所属 ...
- nodejs模块之http&&url
我们使用nodejs中的http模块来进行网络操作 一.什么是HTTP协议: 超文本传输协议(HyperText Transfer Protocol)HTTP假定其下层协议提供可靠传输. 因此,任何能 ...
- import与import static
import ......className (静态导入) 功能: 导入一个类 import static ......className.* 功能:导入这个类里的静态方法,是JDK1.5中的新特性, ...
- Android系统Recovery模式的工作原理【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7464987 在使用update.zip包升级时怎样从主系统(main system)重启进 ...
- Nginx初步配置
编辑 简介 Nginx ("engine x") 是一个轻量级,高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为 ...
- DELPHI-Delphi常用类型及定义单元
DELPHI-Delphi常用类型及定义单元 Type Unit Date SysUtils DeleteFile SysUtils or Windows (different versions) D ...
- 1.SVN
1.SVN安装 SVN服务器端VisualSVN Server(64位OS必须装64位VisualSVN-Server,默认端口是443). 就像建立数据库一样,需要先在svn服务器VisualSVN ...
- QQ.PC管家进程
1.家里的笔记本 WIn7x64 C:\Program Files (x86)\Tencent\QQPCMgr\12.10.19266.225\QMDL.exeC:\Program Files (x8 ...