【发布时间】:2019-04-30 02:31:55
【问题描述】:
这是我们用来构建 LL 的伪代码:
FUNCTION push(element)
CREATE node
SET node.value TO element
SET node.next TO null
IF the head node does not exist
THEN SET head to node
ELSE
SET current to head
SET current.next to node
END IF
END FUNCTION
伪代码本身也有错误。
以下是我尝试遵循的,但现在它正在指向 到推函数中的 { 右侧。
let head = null,
last,
node,
current,
value = element;
const linkedList = () => {
let node = new Node(value);
push(value) {
if(head === null) {
head = last = node;
} else {
last.next = node;
last = node;
}
}
}
Error : push(value) {
【问题讨论】:
-
这是作业吗?
-
“伪代码本身也有错误”——但你不会告诉我们它是什么?
-
什么是"`它指向{
" mean?? Are you getting a compiler error? If so, tell us what it says. How can we help you otherwise? And which{`?有几个 -
这是我正在做的练习
-
添加了最后一行以阐明错误的位置