>  기사  >  웹 프론트엔드  >  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 =
}; getPrev = 함수() {
return this.prev;
};
Dare.LinkedListNode.prototype.setPrev = 함수(노드) {
this.prev = 노드; 🎜> Dare.LinkedListNode.prototype.getNext = 함수() {
return this.prev;
};
Dare.LinkedListNode.prototype.setNext = 함수(노드) {
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)
if (node ​​​​== null) return;
var tail = this.tail;
if (tail == null) {
this.tail = this.head = node
else {
tail.next = 노드;
node.prev = tail;
this.length
}; node
*/
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 (노드 ​​== this.head) {
this.head = node. next;
}
//Tail 노드
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 (노드 ​​== null || obj == null) return;
node.data =
return node;
/*
* 노드 데이터 가져오기
*/ 🎜>Dare.LinkedList.prototype.getNodeData = 함수(노드) {
if (노드 ​​== 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;
};
/*
* 이전 노드
*/
Dare.LinkedList.prototype.prevNode = function () {
if (this == null) return; >if (this.current == null) return
var node = this.current;
return node
/*
* 연결된 목록이 비어 있는지 여부
*/
Dare.LinkedList.prototype.isempty = function () {
if (this == null) return
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;
}
}


실제 호출 사용 사례 코드가 차례로 업데이트됩니다.




코드 복사


코드는 다음과 같습니다.


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.