title: print() function that prints the contents of each element of your list
body: <p>Basically i'm trying to write a print statement that will allow me to print the elements per line as a println as the output when i run the driver.java. And for the life of me i cannot figure out how to do it. Any help will be appreciated. </p>
  
  <p>here is the driver.java</p>
  
  <pre><code>public class Driver {
  
  public static void main(String args[]){
  
  
  
      LList&lt;String&gt; s_list = new LList&lt;String&gt;();
  
      s_list.insert("New York, 8.4M");
      s_list.insert("Los Angeles 3.8M");
      s_list.insert("Chicago, 2.7M");
      s_list.insert("Houston, 2.1M");
      s_list.insert("Philadelphia, 1.55M");
      s_list.insert("Phoenix, 1.51M");
      s_list.append("San Antonio, 1.4M");
      s_list.append("San Diego, 1.35M");
      s_list.append("Dallas, 1.25M");
      s_list.append("San Jose, 0.998M");
      s_list.append("Austin, 0.88M");
      s_list.append("Indianapolis, 0.84M");
      s_list.append("Jacksonville, 0.84M");
      s_list.append("San Francisco, 0.83M");
      s_list.append("Columbus, 0.82M");
      s_list.append("Charlotte, 0.79M");
  
      s_list.print();
      s_list.moveToPos(3);
      s_list.remove();
      s_list.print();
      s_list.moveToEnd();
      s_list.remove();
      s_list.print();
      s_list.moveToStart();
      s_list.remove();
      s_list.remove();
      s_list.print();
      s_list.clear();
      s_list.print();
  
  
  }
  
  }
  </code></pre>
  
  <p>and I have a java file named LList.java</p>
  
  <p>where I am trying to write a print method where it will print() function that prints the contents of  each element of your list; print one element per line.</p>
  
  <pre><code>public void print { 
  
  }   
  </code></pre>
  
  <p>So, How will i print the elements in "s_list" line per line as output.</p>
  
  <p>Any help is appreciated.</p>
  
  <hr>
  
  <p>UPDATE: I am going to post Llist.java,list.java &amp; link.java here</p>
  
  <p>Llist.java</p>
  
  <pre><code> /** Linked list implementation */ 
  
   class LList&lt;E&gt; implements List&lt;E&gt; { 
   private Link&lt;E&gt; head; // Pointer to list header 
   private Link&lt;E&gt; tail; // Pointer to last element 
  protected Link&lt;E&gt; curr; // Access to current element 
   private int cnt; // Size of list 
   /** Constructors */ 
   LList(int size) { this(); } // Constructor -- Ignore size 
   LList() { 
   curr = tail = head = new Link&lt;E&gt;(null); // Create header 
    cnt = 0; 
   } 
  /** Remove all elements */ 
  public void clear() { 
  head.setNext(null); // Drop access to links 
  curr = tail = head = new Link&lt;E&gt;(null); // Create header 
  cnt = 0; 
  } 
  /** Insert "it" at current position */ 
  public void insert(E it) { 
  curr.setNext(new Link&lt;E&gt;(it, curr.next())); 
  if (tail == curr) tail = curr.next(); // New tail 
  cnt++; 
  } 
  /** Append "it" to list */ 
  public void append(E it) { 
  tail = tail.setNext(new Link&lt;E&gt;(it, null)); 
  cnt++; 
  } 
  /** Remove and return current element */ 
  public E remove() { 
  if (curr.next() == null) return null; // Nothing to remove 
   E it = curr.next().element(); // Remember value 
   if (tail == curr.next()) tail = curr; // Removed last 
  curr.setNext(curr.next().next()); // Remove from list 
  cnt--; // Decrement count 
  return it; // Return value 
  } 
  /** Set curr at list start */ 
  public void moveToStart() 
  { curr = head; } 
  
  /** Set curr at list end */ 
  public void moveToEnd() 
  { curr = tail; } 
  /** Move curr one step left; no change if now at front */ 
  public void prev() { 
  if (curr == head) return; // No previous element 
  Link&lt;E&gt; temp = head; 
  // March down list until we find the previous element 
  while (temp.next() != curr) temp = temp.next(); 
  curr = temp; 
  } 
  /** Move curr one step right; no change if now at end */ 
  public void next() 
  { if (curr != tail) curr = curr.next(); } 
  /** @return List length */ 
  public int length() { return cnt; } 
  /** @return The position of the current element */ 
  public int currPos() { 
      Link&lt;E&gt; temp = head; 
      int i; 
      for (i=0; curr != temp; i++) 
          temp = temp.next(); 
      return i; 
  } 
  /** Move down list to "pos" position */ 
  public void moveToPos(int pos) { 
      assert (pos&gt;=0) &amp;&amp; (pos&lt;=cnt) : "Position out of range"; 
      curr = head; 
      for(int i=0; i&lt;pos; i++) curr = curr.next(); 
  } 
  /** @return Current element value */ 
  public E getValue() { 
      if(curr.next() == null) return null; 
      return curr.next().element(); 
  }
  
  public void print()
  {
  
  }   
  
  }
  </code></pre>
  
  <p>List.java</p>
  
  <pre><code>/** List ADT */ 
  public interface List&lt;E&gt; { 
      /** Remove all contents from the list, so it is once again 
  empty. Client is responsible for reclaiming storage 
  used by the list elements. */ 
      public void clear(); 
      /** Insert an element at the current location. The client 
  must ensure that the list�s capacity is not exceeded. 
  @param item The element to be inserted. */ 
      public void insert(E item); 
      /** Append an element at the end of the list. The client 
  must ensure that the list�s capacity is not exceeded. 
  @param item The element to be appended. */ 
      public void append(E item); 
      /** Remove and return the current element. 
  @return The element that was removed. */ 
      public E remove(); 
      /** Set the current position to the start of the list */ 
      public void moveToStart(); 
      /** Set the current position to the end of the list */ 
      public void moveToEnd(); 
      /** Move the current position one step left. No change 
  if already at beginning. */ 
      public void prev(); 
      /** Move the current position one step right. No change 
  if already at end. */ 
      public void next(); 
      /** @return The number of elements in the list. */ 
      public int length(); 
      /** @return The position of the current element. */ 
      public int currPos(); 
      /** Set current position. 
  @param pos The position to make current. */ 
      public void moveToPos(int pos); 
      /** @return The current element. */ 
      public E getValue(); 
  } 
  </code></pre>
  
  <p>Link.java</p>
  
  <pre><code>/** Singly linked list node */ 
  class Link&lt;E&gt; { 
  
      private E element; // Value for this node 
      private Link&lt;E&gt; next; // Pointer to next node in list 
      // Constructors 
      Link(E it, Link&lt;E&gt; nextval) 
      { element = it; next = nextval; } 
      Link(Link&lt;E&gt; nextval) { next = nextval; } 
      Link&lt;E&gt; next() { return next; } // Return next field 
      Link&lt;E&gt; setNext(Link&lt;E&gt; nextval) // Set next field 
      { return next = nextval; } // Return element field 
      E element() { return element; } // Set element field 
      E setElement(E it) { return element = it; } 
  } 
  </code></pre>