栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

js实现双向链表互联网机顶盒实战应用实现

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

js实现双向链表互联网机顶盒实战应用实现

上实战代码:
linkedlistnode.js 节点类
复制代码 代码如下:

Dare.linkedListNode = function () {
this.data = null;//数据域
this.prev = null;//前驱
this.next = null;//后驱
};
Dare.extend(Dare.linkedListNode, Dare);
Dare.linkedListNode.prototype.getValue = function () {
return this.data;
};
Dare.linkedListNode.prototype.setValue = function (obj) {
this.data = obj;
};
Dare.linkedListNode.prototype.getPrev = function () {
return this.prev;
};
Dare.linkedListNode.prototype.setPrev = function (node) {
this.prev = node;
};
Dare.linkedListNode.prototype.getNext = function () {
return this.prev;
};
Dare.linkedListNode.prototype.setNext = function (node) {
this.prev = node;
};

linkedlist.js 链表类
复制代码 代码如下:

Dare.linkedList = function () {
this.head = null;
this.current = null;
this.tail = null;
this.length = 0;
};
Dare.extend(Dare.linkedList, Dare);

Dare.linkedList.prototype.appendNode = function (node) {
if (this == null) return;
if (node == null) return;
var tail = this.tail;
if (tail == null) {
this.tail = this.head = node;
}
else {
tail.next = node;
node.prev = tail;
this.tail = node;
}
this.length++;
};

Dare.linkedList.prototype.moveNode = function (node) {
if (this == null) return;
if (node == null) return;
//中间节点
var prev = node.prev;
if (prev != null) {
prev.next = node.next;
}
if (node.next != null) {
node.next.prev = prev;
}
//头节点
if (node == this.head) {
this.head = node.next;
}
//尾节点
if (node == this.tail) {
if (prev != null) {
this.tail = prev;
}
else {
this.head = this.tail;
}
}
node.prev = null;
node.next = null;
this.length--;
};

Dare.linkedList.prototype.constructNode = function (node, obj) {
if (node == null || obj == null) return;
node.data = obj;
return node;
};

Dare.linkedList.prototype.getNodeData = function (node) {
if (node == null) return;
return node.data;
};

Dare.linkedList.prototype.start = function () {
if (this == null) return;
return this.current = this.head;
};

Dare.linkedList.prototype.end = function () {
if (this == null) return;
return this.current = this.tail;
};

Dare.linkedList.prototype.nextNode = function () {
if (this == null) return;
if (this.current == null) return
var node = this.current;
this.current = this.current.next;
return node;
};

Dare.linkedList.prototype.prevNode = function () {
if (this == null) return;
if (this.current == null) return
var node = this.current;
this.current = this.current.prev;
return node;
};

Dare.linkedList.prototype.isempty = function () {
if (this == null) return true;
if (this.head == null) {
return true;
}
else {
return false;
}
};

Dare.linkedList.prototype.getLength = function () {
if (this == null) return;
return this.length;
};

Dare.linkedList.prototype.clearList = function () {
this.head.next = null;
this.head = null;
};

Dare.linkedList.prototype.containsNode = function (obj) {
if (this == null) return false;
var node = list.head;
if (node == null) return false;
while (node != null) {
if (node.data == obj) {
return true;
}
node = node.next;
}
};

实战调用用例代码陆续更新:
复制代码 代码如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/113638.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号