javascript 数据结构链表 - addToHead()addToTail() - https://repl.it/@plastikaweb/LightblueTomatoRaven
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 数据结构链表 - addToHead()addToTail() - https://repl.it/@plastikaweb/LightblueTomatoRaven相关的知识,希望对你有一定的参考价值。
const es6 = require('es6');
function LinkedList() {
this.head = null;
this.tail = null;
}
LinkedList.prototype.addToHead = function(value) {
const newNode = new Node(value, this.head, null);
if (this.head) {
this.head.prev = newNode;
} else {
this.tail = newNode;
}
this.head = newNode;
};
LinkedList.prototype.addToTail = function(value) {
const newNode = new Node(value, null, this.tail);
if (this.tail) {
this.tail.next = newNode;
} else {
this.head = newNode;
}
this.tail = newNode;
};
function Node(value, next, prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
var LL = new LinkedList();
LL.addToHead(100);
LL.addToHead(200);
LL.addToHead(300);
console.log(LL);
以上是关于javascript 数据结构链表 - addToHead()addToTail() - https://repl.it/@plastikaweb/LightblueTomatoRaven的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript数据结构之链表
JavaScript数据结构——链表
数据结构与算法--JavaScript 链表
利用JavaScript和Python实现链表
javascript数据结构-链表
JavaScript数据结构——链表的实现