共计 427 个字符,预计需要花费 2 分钟才能阅读完成。
残缺可运行代码
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)
正文完
发表至: javascript
2022-06-29