<!DOCTYPE html>标签:function,current,57,next,链表,resultString,var,数据结构,data From: https://blog.51cto.com/u_15460007/6049340
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>双向链表</title>
</head>
<body>
<script>
function DoubleList(){
this.head=null
this.tail=null
this.length=0
function Node(data){
this.data=data
this.prev=null
this.next=null
}
DoubleList.prototype.append=function(data){
var newNode=new Node(data)
if(this.length==0){
this.head=newNode
}else{
var current=this.head
while(current.next){
current=current.next
}
current.next=newNode
}
this.length+=1
}
DoubleList.prototype.backwardString=function(data){
//定义变量
var current=this.head
var resultString=""
while(current){
resultString+=current.data+" "
current=current.next
}
return resultString
}
DoubleList.prototype.forwardString=function(data){
//定义变量
var current=this.tail
var resultString=""
while(current){
resultString+=current.data+" "
current=current.prev
}
return resultString
}
DoubleList.prototype.toString=function(data){
//定义变量
return this.backwardString()
}
}
</script>
</body>
</html>