Intro to Linked Lists

  1. A linked list is a dynamically growing/shrinking "data structure" used to organize a collection of identical objects

    The objects are organized into a chain

    The objects are accessed starting from the first object in the chain

  2. How to put objects into a chain...:

  3. Example:

    Example: ListElem class
       public class ListElem
       {
          public int      value;
          public ListElem next;    
    
          ....
       }
    
    

    Example: creating a chain of 2 objects
        ListElem obj1 = new ListElem(1000);
        ListElem obj2 = new ListElem(5000);
     
        obj1.next = obj2;   
    
    

  4. DEMO Example of Java code that chains 2 elements together:

  5. DEMO Example of Java code that chains 5 elements together and shows a general way to print the content of a list:

  6. In general, a chain (list) will look like this:

  7. Summary of list basics:

    Then the confusion begins....

  8. Organizing a linked list: