Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎


posted Dec 16, 2018, 9:05 PM by Konstantinovich Samuel   [ updated Dec 18, 2018, 6:26 AM ]
You most likely SHOULD NOT call getNthNode more than 1 time in the same method!
You can get the next/previous node, so calling it to get the next/previous will add a lot of extra time for no reason!

Let us discuss various ways of writing some of the methods in linked list. 

Connecting two linked lists should be able to happen in constant time!
//New Method:
public class myLinkedList{
   public void extend(MyLinkedList other){
        //in O(1) runtime, move the elements from other onto the end of this
        //The size of other is reduced to 0
        //The size of this is now the combined sizes of both original lists