嗨 我写了这样一个代码,我想知道:它的时间复杂度是 O(n) ?
DNode header = new DNode(null, null, null);
DNode trailer = new DNode(null, header, null);
header.next = trailer;
for (Point point : pointList) {
DNode node = new DNode(point, header, trailer);
dList.addLast(node);
header = node;
}
我想将所有对象从pointList(ArrayList)
复制到dList(双向链接列表)
。
谢谢
最佳答案
是的。这里只有一个明显的循环,即 O(n) - 假设双向链表的合理实现,循环内的所有内容都是 O(1)。
关于java - 这个 while 循环的时间复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4264067/