js--数据结构--链表
来源:互联网 发布:sql注入绕过 concat 0x 编辑:程序博客网 时间:2024/06/07 17:36
链表是一种线性结构,每一个节点中,储存了下一个节点的指针。
1.链表的构造函数,属性是头指针和长度
2.节点的构造函数,属性是element值和指向下个节点的指针
3.原型方法
append(element): 添加元素到链表尾部.
insert(position,element): 向单向链表中某个位置插入元素
indexOf(element): 寻找某个元素在单向链表中的位置
remove(element): 移除给定的元素
removeAt(position): 移除单向链表中某个位置的元素
getHead(): 获取单向链表的头部
isAmpty(): 检查单向链表是否为空,为空则返回true
toString(): 将链表所有内容以字符串输出
size(): 返回单向链表长度
append: 添加元素到链表尾部.
创建新节点元素,如果头节点为null,则头指针指向新节点。如果不是,while循环到最后一个,从而将该节点加入链表尾部。
insert:
indexOf:寻找某个元素在单向链表中的位置
function Node(element){ this.element = element; this.next = null;}function LinkedList(){ this.head = null; this.length = 0;}LinkedList.prototype = { constructor:LinkedList, append:function(element){ var node = new Node(element), current; if(this.head == null){ this.head = node; } else { current = head; while(current.next) { current = current.next; } current.next = node; } this.length++; }, insert:function(){ }, indexOf:function(element){ var current = this.head, index = -1; while(current){ if(element === current.element) { return index; } } },}
0 0
- js--数据结构--链表
- JS数据结构:链表
- 数据结构--链表(js版)
- js数据结构和算法----链表
- js数据结构
- js--数据结构--树
- js的数据结构
- JS数据结构案例
- JS数据结构之---数组
- JS数据结构: 队列
- JS数据结构:哈希表
- js-es6-set数据结构
- js-es6-Map数据结构
- JS中的数据结构
- JS数据结构与算法--字典
- 数据结构--图(js版)
- 数据结构--栈(js版)
- js数据结构之链表
- SpringAnnotation注解之@Resource
- hduoj 2030统计汉字
- SpringAnnotation注解之@Autowired
- SpringAnnotation之配置AnnotationXML文件
- Spring的AOP介绍
- js--数据结构--链表
- HBase Java简单示例
- Annotation方式实现AOP
- AOP的Advice
- 翻硬币(搜索)
- XML方式实现Spring的AOP
- Spring简单与数据库连接
- Spring整合Hibernate:1、annotation方式管理SessionFactory
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理