user472221
user472221

Reputation: 3114

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 = 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

Upvotes: 0

Views: 1465

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500535

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.

Upvotes: 3

Related Questions