I am having some trouble sorting a vector by comparing the elements finding the minimum and putting it in another vector that will be the sorted one using two cycles, in particular i keep having ArrayIndexOutOfBoundsException.
Vector<Figure> myList = new Vector<Figure>(); //this is the vector with all the unsorted geometric shapes
Vector<Figure> listordered = new Vector<Figure>(); //the vector where i want to put them sorted
Figure x = null;
int indice = 0;
System.out.println(myList.size());
do{
for(int i=0;i<myList.size();i++) {
x = myList.get(i);
if(x.compareTo(MIN) <0)
MIN=x;
indice = myList.indexOf(MIN);
}
listordered.add(MIN);
myList.removeElementAt(indice);
System.out.println(myList.size());
}while(myList.size()!=0);
System.out.println(listordered);
My idea was to find the minimum with a cycle then add it to the sorted vector and with another cycle keep doing this untill there were no more elements in the first vector and removing each time the new minimum element found. but it doesnt work.