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格式.当年照着视频学习的时候记录下来的,在使用的时候直接拿来修改修改修改能节约不少时间的. /********************* ...
随机推荐
- IImage--factory
<?php /* 实例4 */ /* 使用工厂类解析图像工作 */ interface IImage { function getWidth(); function getHeight(); f ...
- java WEB学习笔记32:HttpSession 接口常用方法 及 HttpServletRequest接口中的Session方法 Demo
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 开发rsync启动脚本2
使用函数更加规范的开发rsync启动脚本 #!/bin/bash #chkconfig: #description: create by vincen . /etc/init.d/functions ...
- 大话设计模式--建造者模式 Builder -- C++实现实例
1. 建造者模式,将一个复杂对象的构建与它的表示分离, 使得同样的构建过程可以创建不同的表示. 用户只需要指定需要建造的类型就可以得到他们,而具体建造的过程和细节就不需要知道了. 关键类Directo ...
- Neutron Messaging Callback System
callback system 用在进程内部通信,Messaging Callback System是给进程间通信.为了agent不通过RPC就能得到resource的变化. 目前用在: QoS po ...
- unity3D编辑器扩展
编辑器扩展只是在编辑项目中运行,发布出来是不会运行的. 固定创建一个文件夹Editor:所有的资源或者代码都不会被打包进去. 01.使用MenuItem添加菜单栏按钮 脚本不需要作为组件存在,可以不用 ...
- Hibernate学习---第十节:Hibernate之QBC、样例查询&离线查询
一.QBC (Query By Criteria) 主要有Criteria,Criterion,Oder,Restrictions类组成 1.java 代码如下: /** * 查询所有 */ @Tes ...
- python_doc 读写docx文件
python读写word文档有现成的库可以处理,在这里采用了 python-docx. 首先先安装 pip install python-docx #!/usr/bin/env python # -* ...
- ES field store yes no 区别——可以设置为false,如果_source有的话
store By default, field values are indexed to make them searchable, but they are not stored. This me ...
- 实现html表头固定,表格内的信息向上滚动
效果如下: <!doctype html>Table header header two fuck 1 fuck 2 fuck 1 fuck 2 fuck 1 fuck 2 fuck 1 ...