开发者

time complexity of this while loop

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 = ne开发者_StackOverfloww 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜