ホームページ  >  記事  >  ウェブフロントエンド  >  jsでダブルリンクリストを実装 インターネットセットトップボックスの実践応用実装_javascriptスキル

jsでダブルリンクリストを実装 インターネットセットトップボックスの実践応用実装_javascriptスキル

WBOY
WBOYオリジナル
2016-05-16 18:00:091034ブラウズ

実際のコード:
linkedlistnode.js ノード クラス

コードをコピー コードは次のとおりです:

/*
* リンク リスト ノード
*/
Dare.LinkedListNode = function () {
this.data = null;//データ フィールド
this.prev = null;/ /Precursor
this.next = null;//Backdrive
};
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 = ノード; 🎜> Dare.LinkedListNode.prototype.getNext = function () {
return this.prev;
};
Dare.LinkedListNode.prototype.setNext = function (node) {
this.prev =ノード;
};


linkedlist.js リンク リスト クラス



コードをコピーします。は次のとおりです。
/* * 二重リンクリスト*/ Dare.LinkedList = function () { this.head = null; this.current = null;
this.tail = null;
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 = ノード;
else {
tail.next = ノード;
ノード.prev = テイル;
}
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 = ノード。 next;
}
//テールノード
if (node == this.tail) {
if (prev != null) {
this.tail = prev; >}
else {
this.head = this .tail;
}
node.prev = null;
node.next = null; --;
};
/*
* ノードを構築します
*/
Dare.LinkedList.prototype.constructNode = function (node, obj) {
if (node == null || null) return;
ノード;
/*
* ノードデータを取得します。 🎜>Dare.LinkedList.prototype.getNodeData = function (node) {
if (node == null) return;
/*
* 最初から始める
*/
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 ノード = this.current;
this.current = this.current.next;
};
/*
* 前のノード
*/
Dare.LinkedList.prototype.prevNode = function () {
if (this == null) return; >if (this.current == null) return
var ノード = this;
return ノード;
;
* リンクされたリストが空かどうか
*/
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;
/* * リンクされたリストをクリアします
*/
Dare.LinkedList.prototype.clearList = function () {
this.head.next = null;
this.head = null; ;
/*
* ノードが存在するかどうか
*/
Dare.LinkedList.prototype.containsNode = function (obj) {
if (this == null) return
var node = list.head;
if (node == null) return false;
while (node != null) {
if (node.data == obj) {
return true;
}
node = node.next;
}
}


実際の呼び出しユースケースのコードは次のように更新されます。 >


コードをコピーします


コードは次のとおりです:


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。