title: sorting a doubly linked list with merge sort
body: <p>I have found this code in the internet and it was for arrays ,I want to change it for doubly linked list(instead of index we should use pointer) would you please help me that how can i change merge method(I have changed sort method by myself) also this is not my home work ,I love working with linked list!!</p>
  
  <pre><code>public class MergeSort {
  
  private DoublyLinkedList LocalDoublyLinkedList;
  
  public MergeSort(DoublyLinkedList list) {
      LocalDoublyLinkedList = list;
  
  }
  
  public void sort() {
  
      if (LocalDoublyLinkedList.size() &lt;= 1) {
          return;
      }
      DoublyLinkedList listOne = new DoublyLinkedList();
      DoublyLinkedList listTwo = new DoublyLinkedList();
      for (int x = 0; x &lt; (LocalDoublyLinkedList.size() / 2); x++) {
          listOne.add(x, LocalDoublyLinkedList.getValue(x));
  }
  for (int x = (LocalDoublyLinkedList.size() / 2) + 1; x &lt; LocalDoublyLinkedList.size`(); x++) {`
      listTwo.add(x, LocalDoublyLinkedList.getValue(x));
  }
  //Split the DoublyLinkedList again
      MergeSort sort1 = new MergeSort(listOne);
      MergeSort sort2 = new MergeSort(listTwo);
      sort1.sort();
      sort2.sort();
  
      merge(listOne, listTwo);
  }
  
  private void merge(DoublyLinkedList a, DoublyLinkedList b) {
      int x = 0;
      int y = 0;
      int z = 0;
      while (x &lt; first.length &amp;&amp; y &lt; second.length) {
          if (first[x] &lt; second[y]) {
              a[z] = first[x];
              x++;
          } else {
              a[z] = second[y];
              y++;
          }
          z++;
      }
  //copy remaining elements to the tail of a[];
      for (int i = x; i &lt; first.length; i++) {
          a[z] = first[i];
          z++;
      }
      for (int i = y; i &lt; second.length; i++) {
          a[z] = second[i];
          z++;
      }
  }
  }
  </code></pre>