now supports sorting

This commit is contained in:
amontano 2003-07-25 01:43:58 +00:00
parent 97f5fe91b3
commit 5df9b5b91a

View file

@ -49,6 +49,27 @@ public class SimplifiedLinkedList
else cabeza = cabeza.createPrevious(o); else cabeza = cabeza.createPrevious(o);
} }
public void addSorted(Comparable o)
{
Link previous, currentLink, temp;
if (cabeza==null || o.compareTo(cabeza.get())<0)
{
addLast(o);
}
else
{
currentLink = cabeza;
do
{
previous = currentLink;
currentLink = currentLink.next();
} while ((currentLink != null) && (o.compareTo(currentLink.get())>=0));
temp = new Link (o);
previous.siguiente = temp;
temp.siguiente = currentLink;
}
}
public Object getLast() public Object getLast()
{ {
if (cabeza==null) return null; if (cabeza==null) return null;