简体   繁体   中英

Is jdk provided doubly linked list circular?

Is java doubly linked list circular ?

It nowhere written in java docs. But looks likes its circular when i see linked list source code Here is the relevant code snippet if

private Entry<E> More ...entry(int index) {
...
        Entry<E> e = header;
        if (index < (size >> 1)) {
           ...
        } else {
             for (int i = size; i > index; i--)
                e = e.previous;
        }
        return e;
    }

Update :- By circular i mean

  1. header previous node should be last node which seems true here
  2. And for last node next node should be header node

Going by your criteria

  1. header previous node should be last node which seems true here
  2. And for last node next node should be header node

Linked list is circular because if you see add method implementation which internally calls addBefore , entry you going to insert points to header as next link and header points to last entry you just inserted as previous link

It's not circular. It has a clear Head and Tail.

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