Skip to content

Adding linked lists to each other #108149

Answered by EgorBo
ABehniwal asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a way I can do this without having to iterate through the linked list and add each element individually.

It's not possible to have an O(1) insert of one LinkedList into another without side-effects. E.g. if you add list1 into list2 without iterating, then if you remove an element from list2 it will be, effectively, removed from list1 as well.

Linked List is not a complicated data structure, if you need a fast merge (and are fine with the side-effects) you can roll your own fairly quickly.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ABehniwal
Comment options

Answer selected by ABehniwal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants