日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/6/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 js实现双向链表互联网机顶盒实战应用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

上實(shí)戰(zhàn)代碼:

linkedlistnode.js 節(jié)點(diǎn)類

/*
* 鏈表節(jié)點(diǎn)
*/
Dare.LinkedListNode = function () {
? this.data = null;//數(shù)據(jù)域
? this.prev = null;//前驅(qū)
? this.next = null;//后驅(qū)
};
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);
/*
* 尾插法添加節(jié)點(diǎn)
*/
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++;
};
/*
* 刪除節(jié)點(diǎn)
*/
Dare.LinkedList.prototype.moveNode = function (node) {
? if (this == null) return;
? if (node == null) return;
? //中間節(jié)點(diǎn)
? var prev = node.prev;
? if (prev != null) {
??? prev.next = node.next;
? }
? if (node.next != null) {
??? node.next.prev = prev;
? }
? //頭節(jié)點(diǎn)
? if (node == this.head) {
??? this.head = node.next;
? }
? //尾節(jié)點(diǎn)
? if (node == this.tail) {
??? if (prev != null) {
????? this.tail = prev;
??? }
??? else {
????? this.head = this.tail;
??? }
? }
? node.prev = null;
? node.next = null;
? this.length--;
};
/*
* 構(gòu)造節(jié)點(diǎn)
*/
Dare.LinkedList.prototype.constructNode = function (node, obj) {
? if (node == null || obj == null) return;
? node.data = obj;
? return node;
};
/*
* 獲取節(jié)點(diǎn)數(shù)據(jù)
*/
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;
};
/*
* 下個(gè)節(jié)點(diǎn)
*/
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;
};
/*
* 上個(gè)節(jié)點(diǎn)
*/
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;
? }
};
/*
* 鏈表長(zhǎng)度
*/
Dare.LinkedList.prototype.getLength = function () {
? if (this == null) return;
? return this.length;
};
/*
* 清空鏈表
*/
Dare.LinkedList.prototype.clearList = function () {
? this.head.next = null;
? this.head = null;
};
/*
* 是否存在節(jié)點(diǎn)
*/
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;
? }
};?

實(shí)戰(zhàn)調(diào)用用例代碼陸續(xù)更新:

?

?

<script type="text/javascript">
??? var linkedList = new Dare.LinkedList();
??? function createList() {
????? for (var i = 0; i < 7; i++) {
??????? var movie = {};
??????? var linkedListNode = new Dare.LinkedListNode();

??????? movie.id = i;
??????? movie.name = 'movie_' + i;
??????? linkedListNode.data = movie;
??????? linkedList.appendNode(linkedListNode); //創(chuàng)建鏈表
????? }
????? //deleteNode(linkedList);//刪除節(jié)點(diǎn)
????? //printList(linkedList); //輸出鏈表
????? printNode(linkedList);
??? }
??? function printList(list) {
????? var node = list.head;
????? if (node == null) return;
????? var html = '';
????? while (node != null) {
??????? var movie = node.data;
??????? html += movie.id + "|" + movie.name + "<br>";
??????? node = node.next;
????? }
????? document.write(html);
??? }
??? function deleteNode(list) {
????? var node = list.head;
????? if (node == null) return;
????? var i = 0;
????? while (node != null) {
??????? if (i == 3) {
????????? linkedList.moveNode(node); //刪除指定節(jié)點(diǎn)
????????? break;
??????? }
??????? i++;
??????? node = node.next;
????? }
??? }
??? var printNode = function(list) {
????? var node = list.head;
????? if (node == null) return;
????? var i = 0;
????? while (node != null) {
??????? if (i == 4) {
????????? var movie = linkedList.getNodeData(node); //打印指定節(jié)點(diǎn)
????????? document.writeln(movie.id + "<br>");
????????? document.writeln(movie.name + "<br>");
????????? break;
??????? }
??????? i++;
??????? node = node.next;
????? }
??? }
? </script>

?

轉(zhuǎn)載于:https://www.cnblogs.com/fx2008/archive/2011/10/27/2226911.html

總結(jié)

以上是生活随笔為你收集整理的js实现双向链表互联网机顶盒实战应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。