function LinkedList() {
var Node = function(element) {
this.element = element;
this.next = null
}
var length = 0;
var head = null;
this.append = function(element) {
var node = new Node(element),
current;
if (head == null) {
head = node
} else {
current = head;
while (current.next) {
current = current.next
}
current.next = node
}
length++
}
this.insert = function(position, element) {
if (position >= 0 && position <= length) {
var node = new Node(element),
current = head,
previous,
index = 0;
if (position == 0) {
node.next = current;
head = node
} else {
while (index++<position) {
previous = current;
current = current.next
}
node.next = current;
previous.next = node
}
length++;
return true
} else {
return false
}
}
this.removeAt = function(position) {
if (position > -1 && position < length) {
var current = head,
previous, index = 0;
if (position == 0) {
head = current.next
} else {
while (index++<position) {
previous = current;
current = current.next
}
previous.next = current.next
}
length--;
return current.element
} else {
return null
}
}
this.remove = function(element) {
var index = this.indexOf(element);
return this.removeAt(index)
}
this.indexOf = function(element) {
var current = head,
index = -1;
while (current) {
if (element == current.element) {
return index
}
index++;
current = current.next
}
return - 1
}
this.isEmpty = function() {
return length == 0
}
this.size = function() {
return length
}
this.getHead = function() {
return head
}
this.toString = function() {
var current = head,
string = '';
while (current.next) {
string = current.element;
current = current.next
}
return string
}
this.print = function() {}
}
var linkedList = new LinkedList();
linkedList.append("shidengyun");
linkedList.insert(0, 'zhujing');
console.log(linkedList.toString());

JavaScript LinkedList的更多相关文章

  1. javascript LinkedList js 双向循环链表 Circular Linked List

    javascript LinkedList: function Node(elem, prev, next) { this.elem = elem; this.prev = prev ? prev : ...

  2. javascript linkedlist data structures

    在使用C++的时候我们经常会使用到各种容器,这些容器其实就是一种数据结构.在java中其实也是如此.但是由于javascript只给我们提供了一种内置的数据结构数组,准备来说是对象.没有我们常见的那些 ...

  3. 用JavaScript来实现链表LinkedList

    本文版权归博客园和作者本人共同所有,转载和爬虫请注明原文地址. 写在前面 好多做web开发的朋友,在学习数据结构和算法时可能比较讨厌C和C++,上学的时候写过的也忘得差不多了,更别提没写过的了.但幸运 ...

  4. 【JavaScript数据结构系列】05-链表LinkedList

    [JavaScript数据结构系列]05-链表LinkedList 码路工人 CoderMonkey 转载请注明作者与出处 ## 1. 认识链表结构(单向链表) 链表也是线性结构, 节点相连构成链表 ...

  5. 学习javascript数据结构(二)——链表

    前言 人生总是直向前行走,从不留下什么. 原文地址:学习javascript数据结构(二)--链表 博主博客地址:Damonare的个人博客 正文 链表简介 上一篇博客-学习javascript数据结 ...

  6. 数据结构与算法之链表-javascript实现

    链表的定义: 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每个结点 ...

  7. javascript数据结构和算法

    一.栈 javascript实现栈的数据结构(借助javascript数组原生的方法即可) //使用javascript来实现栈的数据结构 var Stack={ //不需要外界传参进行初始化,完全可 ...

  8. javascript中的链表结构

    1.定义 很多编程语言中数组的长度是固定的,就是定义数组的时候需要定义数组的长度,所以当数组已经被数据填满的时候,需要再加入新的元素就很困难.只能说在部分变成语言中会有这种情况,在javascript ...

  9. 《数据结构与算法JavaScript描述》

    <数据结构与算法JavaScript描述> 基本信息 作者: (美)Michael McMillan 译者: 王群锋 杜欢 丛书名: 图灵程序设计丛书 出版社:人民邮电出版社 ISBN:9 ...

随机推荐

  1. WinForm的RadioButton使用小技巧

    http://www.cnblogs.com/sjrhero/articles/1883155.html 当多个RadioButton同在一个容器里面的时候,多半的操作都是要得到其中一个的值这个时候我 ...

  2. 01-HTML控件

    1.HTML (常用标签 网页的基本结构)2.CSS (常用样式 网页的显示效果)3.JavaScript (用户交互效果 动态效果)4.jQuery (JavaScript库 简化原生js操作)5. ...

  3. spark复习笔记(2)

    之前工作的时候经常用,隔了段时间,现在学校要用学的东西也忘了,翻翻书谢谢博客吧. 1.什么是spark? Spark是一种快速.通用.可扩展的大数据分析引擎,2009年诞生于加州大学伯克利分校AMPL ...

  4. vue.js(16)--vue的组件

    注册一个全局组件 <div id="app"> <test></test> </div> <script> // 注册全 ...

  5. vue主动刷新页面及列表数据删除后的刷新方法

    在继刷新当前页面,重载页面数据那篇之后 那一篇 深入理解数据驱动 以上算是开发过程中的一个坑,用了一段时间,今天再读代码的时候,感觉被坑的很严重. 1. 获取列表方法 2.重新获取数据 3.这样再次调 ...

  6. 用C#实现获取文件夹大小的源代码

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  7. Lamabda Where Select Find First等区别

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  8. 【学习】011 JVM参数调优配置

    自动内存管理机制 Java虚拟机原理 所谓虚拟机,就是一台虚拟的机器.他是一款软件,用来执行一系列虚拟计算指令,大体上虚拟机可以分为 系统虚拟机和程序虚拟机, 大名鼎鼎的Visual Box.Vmar ...

  9. 阿里云轻应用云服务器配置tomcat

    #etc/profile export CATALINA_HOME=/wocloud/tomcat_cluster/tomcat1/apache-tomcat-7.0.57 #查看防火墙状态 fire ...

  10. jmeter性能工具 之 cookie 管理器 (二)

    上一篇主要介绍了jmeter 的基本使用方法,编写了登陆脚本,这一篇在登陆基础上,进行充值操作. 问:什么时候需要用到cookied 管理器? 答:需要登陆信息时,如果充值,提现,淘宝的下单,添加到购 ...