完整可运行代码
class Node{
constructor(data) {
this.data = data
this.next = null
}
}
class LinkedList{
constructor() {
this.head = null
this.length = 0
}
append(data) {
const newNode = new Node(data)
if (this.length === 0) {
this.head = newNode
} else {
let current = this.head
while (current.next) {
current = current.next
}
current.next = newNode
}
this.length++
}
}
//
const linkedList = new LinkedList()
linkedList.append('AA')
linkedList.append('BB')
linkedList.append('CC')
console.log(linkedList)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。