简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM