»Dysfunction«
Joseph   Newark, New Jersey, United States
 
 
public void sort()
{
int count=1;
boolean eraseLeftOver=false;
Comparable previousCompare=null;
//Start from the second node in the doubly linked list to the end
//iterator=second Node
for(DLNode<E> iterator=getFirstNode().getNext();iterator.getElement()!=null;iterator=iterator.getNext())
{
//if hit is true, it removes the previous value which is the leftover node
//that was moved up the list in the last iteration
if(eraseLeftOver==true)
{
remove(iterator.getPrev());
eraseLeftOver=false;
}

//currentString is the element as a string at current node e
//previousString is the previous element as a string from current node e
int c=count;
Comparable currentCompare= (Comparable)iterator.getElement();
if(iterator.getPrev().getElement()!=null)
{previousCompare= (Comparable)iterator.getPrev().getElement();}
else
previousCompare="";
//if currentString is less than previousString
if(c>0 && currentCompare.compareTo(previousCompare)<0)
{
//t is the set to be the previous element in the node
DLNode<E> previousIterator=iterator.getPrev();
//iterate through each previous element and compare the previous element to it
//if it's greater or equal to, break the loop, otherwise set t to be the next previous element
for(int k=c;k>0;k--)
{
Comparable previousComparableIterator=(Comparable)previousIterator.getElement();
if(currentCompare.compareTo(previousComparableIterator)>=0)
{
break;
}
previousIterator=previousIterator.getPrev();
}
//Create a temporary variable n holding e's element and add it after the next lowest value
DLNode<E> n=new DLNode<E>(iterator.getElement());
addAfter(previousIterator,n);
c--;
//set hit to true
eraseLeftOver=true;
}
count++;
}
//For the last value in the doubly linked array
//Does the same as above
if(eraseLeftOver==true)
{
remove(getLastNode());
eraseLeftOver=false;
}
}
Currently Online