var someList = {
data : 1,
next : {
data : 2,
next : {
data : 3,
next : {
data : 4,
next : null
}
}
}
};
var ar = [];
function reversePrint(LList)
{
var c = null;
c = LList;
while (c.next != null)
{
ar.unshift(c.data);
c = c.next;
}
console.log(ar);
}
此例程以相反的顺序输出数组。遍历Javascript链接列表跳过最后一项
问题是:循环没有得到data : 4
。
如何重写它以输出所有数据?
我想你想一个do {} while循环,因为据推测,如果接下来的是空,你希望它中止循环之前仍然retreive价值? – NibblyPig 2011-06-16 13:52:40