title: How to implement insert and sort method Comparable array with double link list in java
body: <p>I need help please, I tried to answer but it there a problem.</p>
  <p><strong>My question is:</strong></p>
  <p>Use the addAtFirstSmaller (T t) method to implement Insertion to sort a Comparable array a.</p>
  <p>The implementation will be very simple with the method above.</p>
  <p>1: Create a DoublyLinkedList list.call it a list.</p>
  <p>2: Iterate over the array a. For each element t in a, add t to list by:
  lista.addAtFirstSmaller (t);</p>
  <p>3: Iterate over the list and place the respective elements in the corresponding place in a.
  I have method addAtFirstSmaller (t).it work good.
  I tried in the first tow steps, but I'm not understand how I implement step 3.</p>
  <p>please I need help.</p>
  <pre><code>enter code here
   public Iterator&lt;T&gt; iterator() {
  
   return new Iterator&lt;T&gt;() {
      
           ListNode&lt;T&gt; node = head.next;
  
           @Override
           public boolean hasNext() {
            
                   return node != null;
           }
  
           @Override
           public T next() {
                   
                   if (!hasNext()) {
                           throw new NoSuchElementException();
                   }
                  
                   T elem = node.element;
                 
                   node = node.next;
               
                   return elem;
           }
           @Override
           public void remove() {
           }
       };
      }
  public void addAtFirstSmaller(T t) {
  
  ListNode&lt;T&gt; curr = getLast();
  
   or a node with value &lt; t
  while(curr != head)
  {
      if(curr.element.compareTo(t) &lt; 0) 
          break;
      curr = curr.pre;
  }
  
  if(curr == head) 
  {
      addFirst(t);
  }
  else
  {
    
      ListNode&lt;T&gt; node = new ListNode&lt;T&gt;(curr, curr.pre, t);
     
     
      curr.pre.next = node;
      curr.pre = node; 
  }  
  }
  
  
    enter code here
   public void insertionSort(Comparable[] a) {
      DoublyLinkedList&lt;T&gt; lista = new DoublyLinkedList&lt;T&gt;();
  
        T  t;
        int ind =0;
   
  for(int i = 0; i&lt; a.length; i++) {
       t =  (T) a[i]; 
      
      lista.addAtFirstSmaller(t);
      }
      
      Iterator&lt;T&gt; ite = lista.iterator();
      while(ite.hasNext()) {
       a[ind] = ite.next();
       ind++;
      }
    } 
  
    // TestClass
    public static void main(string[] args){
      Comparable[] a = new Comparable[5];
      DoublyLinkedList&lt;Integer&gt; lista = new DoublyLinkedList&lt;Integer&gt;();
      a[0] = Integer.valueOf(13);
      a[1] = Integer.valueOf(2);
      a[2] = Integer.valueOf(1);
      a[3] = Integer.valueOf(5);
      a[4] = Integer.valueOf(8);
      System.out.println(&quot;The insertion sort för comprable a array is:&quot;);
      lista.insertionSort(a);
      System.out.println(lista);}
  </code></pre>
  <p>I hope help please.</p>