void main() {
List data = [5,4,2,7,8,3];
List sortedData = [];
while (data.isNotEmpty)
{
// pop out the first element
int tmp = data.removeLast();
// while temporary stack is not empty and top
// of stack is greater than temp
while (sortedData.isNotEmpty && sortedData[sortedData.length - 1] > tmp)
{
// pop from temporary stack and push
// it to the input stack
data.addAll(sortedData.removeLast());
}
// push temp in tempory of stack
sortedData.add(tmp);
}
print(data);
print(sortedData);
}
未捕获的错误:TypeError:8:类型'JSInt'不是'Iterable'类型的子类型
我在这里做错了什么?
最佳答案
data.addAll(sortedData.removeLast());
应该是data.add(sortedData.removeLast());