hey Guys
im using this bubble sort to sort an arraylist out but cant seem to output the sorted data out properly! Is there a return method i can use?
Damn ive been stuck hours on this one...
Anyone that could guide me to a solution would be great.
Note: the arrayList entering the bubble parametre in called studTranArray.
Also string sortby is set to "id"
private void bubbleSort(ArrayList<studentClass> sortedList, String sortBy)
{
//start with the first element in the array
for (int outer = 0; outer < sortedList.size() - 1; outer++)
{
//compare "outer" element with rest of elements one by one
//swap if necessary
for (int inner = outer+1; inner < sortedList.size(); inner++)
{
//if sorting by id compare ids
if (sortBy.equalsIgnoreCase("id"))
{
if (sortedList.get(outer).getStudentID() > sortedList.get(inner).getStudentID())
{
swapEm(sortedList, outer, inner);
//displayData(sortedList);
//----------------------here i assumed the end of the sorting was and i could return sorted data to JList
int i = 0;
sortedList = studTranArray;
while (i<studTranArray.size())
{
tranList.addElement(studTranArray.get(i).studentName +" "+ studTranArray.get(i).studentID);
i++;
}
}
}
}
}
}
private void swapEm(ArrayList<studentClass> sortedList, int outer, int inner)
{
studentClass temp = sortedList.get(inner);
sortedList.set(inner, sortedList.get(outer));
sortedList.set(outer, temp);
}
Thanks to any help