I want to make a simple selection sort to sort a small vector. The stuff in the vector has a boolean method called "isBefore" that I can use to do the sort. For some reason, my sort blows up when I do ".removeElementAt...".
Obviously it is trying to remove an element that is not present. However, I cannot see how that could happen! This is driving me insane, please help!
public static Vector sortVector(Vector a)
{
int i=0;
entry champ= new entry();
entry contender= new entry();
int champIndexValue=0;
Vector b = new Vector(100,100);
while(a.size()>0)
{
i=0;
champ=(entry)a.firstElement();
while(i<a.size())
{
contender= (entry) a.elementAt(i);
if(contender.isBefore(champ))
{
champ=contender;
champIndexValue=i;
}
i++;
}
b.add(champ);
a.removeElementAt(champIndexValue);
}
return b;
}
Obviously it is trying to remove an element that is not present. However, I cannot see how that could happen! This is driving me insane, please help!
public static Vector sortVector(Vector a)
{
int i=0;
entry champ= new entry();
entry contender= new entry();
int champIndexValue=0;
Vector b = new Vector(100,100);
while(a.size()>0)
{
i=0;
champ=(entry)a.firstElement();
while(i<a.size())
{
contender= (entry) a.elementAt(i);
if(contender.isBefore(champ))
{
champ=contender;
champIndexValue=i;
}
i++;
}
b.add(champ);
a.removeElementAt(champIndexValue);
}
return b;
}