Is there a fast concat method for linked list in Java?
Posted
by rocker
on Stack Overflow
See other posts from Stack Overflow
or by rocker
Published on 2010-03-22T16:39:27Z
Indexed on
2010/03/22
16:41 UTC
Read the original article
Hit count: 208
How can I concat two linked lists in O(1) with Java via jdk, google or apache commons collection or whatever? E.g. in jdk there is only the addAll method which is O(n).
Another feature I miss is to concat two lists where each of them could be in inverse order. To illustrate this assume two lists a->b->c and e->f->g could merged into
- a->b->c->e->f->g
- a->b->c->g->f->e
- c->b->a->e->f->g
- c->b->a->g->f->e
Do you know of such a list implemenation or do I have to implement my own linked list? It would be also helpful to know how to tweak existing solutions (e.g. the jdk LinkedList has a lot of private methods only). These features seems to me very obvious, hopefully I am not missing something stupid.
© Stack Overflow or respective owner