Hi
I have written such a this code and I want to know that : its time complexity is 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;
}
I want to copying all objects from the pointList(ArrayList) to a dList(Doubly-Linked list).
thanks
Yes. There’s only one obvious loop here, which is O(n) – and everything within the loop is O(1), assuming a sensible implementation of the doubly-linked list.