//js中是没有链表的,但是我们可以用对象的引用来模拟一个链表
// 首先创建一个链表
function CreateNode(data){
this.data = data
this.next = null
}
let a = CreateNode(1)
let b = CreateNode(2)
let c = CreateNode(3)
a.next = b
b.next = c
//此时我们的链表创建完成
// 打印列表
function printLst(head){
while(head){
console.log(head.data)
head = head.next
}
}
printLst(a)
// 翻转链表
// 1-2-3-null
function reverse(head){
let newHead = null
let temp = null
while(head){
temp = head.next
head.next = newHead
newHead = head
head = temp
}
return newHead
}
reverse(a);
10-04
82
08-30
772