title: Homework - Java - Selection Sort on my created double-linked list
body: <p>My assigment is to create my own linked list class (I can't use Java's LinkedList class) and implement a selection sort on it by swapping pointers rather than data.</p>
  
  <p>I've created a double-linked MyLinkedList class, but I'm having trouble with the sort method. I've tried a number of things but nothing has worked - not even anything that would make sense to post here for correction. (I do know that I need to use at least one temp Node.) It has to be a <strong>selection sort</strong>.</p>
  
  <p>I'm not looking for someone to code it for me, necessarily; I'm hoping someone can help me with an algorithm that I can then turn into code myself. Any help is appreciated greatly.</p>
  
  <p>Here's how I've implemented the MyLinkedList class and the associated Node class:</p>
  
  <pre><code>public class MyLinkedList
  {
      private Node head;
      private int count;
  
      public MyLinkedList()
      {
          head = new Node(null);
          count = 0;
      }
  
      public void add(String line)
      {
          Node temp = new Node(line);
          Node current = head;
  
          while (current.getNext() != null)
          {
              current = current.getNext();
          }
  
          temp.setLine (line);  // not sure this is how to do it
          current.setNext(temp);
          temp.setPrev(current);
          count++;
      }
  
      public void displayList()
      {
          Node current = head;
  
          for (int i = 0; i &lt; count; i++)
          {
              current = current.getNext();
              System.out.println(current.getLine());
          }
      }
  
      public void sortList()
      {       
          Node start = head;
          Node index = start;
          Node min = start;
  
          Node temp1, temp2;
  
          while (start.getNext() != null)
          {
              index = index.getNext();
  
              if (index.getLine().compareTo(min.getLine()) &lt; 0)
              {
                  min = index;
              }
  
              //swap - HELP, PLEASE :-)
              {
                  // Algorithm???
              }
          }
      }
  
      public int size()
      {
          return count;
      }
  
  
      private class Node
      {
          String textLine;
          Node next;
          Node prev;
  
          public Node()
          {
              textLine = null;
              next = null;
              prev = null;
          }
  
          public Node (String line)
          {
              textLine = (line);
              next = null;
              prev = null;
          }
  
          public Node (String line, Node node1, Node node2)
          {
              textLine = line;
              prev = node1;
              next = node2;
          }
  
          public String getLine()
          {
              return textLine;
          }
  
          public Node getNext()
          {
              return next;
          }
  
          public Node getPrev()
          {
              return prev;
          }
  
          public void setLine(String line)
          {
              textLine = line;
          }
  
          public void setNext(Node nextNode)
          {
              next = nextNode;
          }
  
          public void setPrev(Node prevNode)
          {
              prev = prevNode;
          }
      }
  }
  </code></pre>