+ 4
A linked list is merely a bunch of objects that each contain a pointer to the next item in the list (i.e. A.next = B, B.next = C, etc.) So lets say that you have a linked list that looks like this: A->B->C And you wish to insert D between B and C. All that you need to do is traverse the list until you get to B and set D.next = B.next. Your list now looks like this: A->B->C D--^ But now you have two things pointing to C and D is still nit on the path from A to C. The final step is to point B to D with B.next = D. Your list should now look like this: A->B->D->C
22nd Jul 2016, 3:45 AM
Colton Lillywhite
Colton Lillywhite - avatar