你可以使用JavaScript的一个简单的链表类来建立一个单链表。 然后,您可以使用一个for循环来遍历每个节点,并使用console.log()函数输出数据。
例如:
class LinkedList {
constructor() {
this.head = null;
this.tail = null;
}
addNode(data) {
const newNode = {
data: data,
next: null
};
if (this.head === nu