I've spend 3 hours searching and attempting to make algorithms myself. I can't figure it out, can someone give me an algorithm to Sort a Linked List Alphabetically?
Here is the last thing I attempted before I gave up the search and decided to ask here
class link
{
public void insertNewFirstNode(String value)
{
StringNode newNode = new StringNode(value, head);
head = newNode;
if(tail==null)
{
tail=head;
}
}
public link sort(link L)
{
link sorted = new link();
StringNode currentNode = head;
while (currentNode != null)
{
int data=0;
if((currentNode.getLink() != null))
{
data=currentNode.getData().compareTo(currentNode.getLink().getData());
if(data==1)
{
sorted.insertNewFirstNode(currentNode.getData());
}
currentNode = currentNode.getLink();
}
else if((currentNode != null))
{
currentNode = currentNode.getLink();
}
}
sorted.reverse();
return sorted;
}
//Other functions
}
if(data==1);- remove last;