Help people hows it going?
I need some help with a bubble sort algorithm, i basically have to use a bubble sort to look through a number of car registration numbers and put them into ascending order...
Im just not quite sure how to get it done... I asked a friend and he gave me this:
public int sortByRegNo()
{
for (int k = list.size(); k > 0; k--)
{
for (int l = 0; l < k-1; l++)
{
if(list.get(l).compareTo(list.get(1 + 1) < 0)
{
swop(l, l+1);
}
}
}
}
He said that id need a swop method and a compareTo method but im not quite sure how to do them can any1 help please?
I had a go at the compare To method:
public int compareTo(Car car) {
return regNo.compareTo(car.getRegNo());
}
But im not to good at Java so not sure if I did it correct or not, obviously didn't as it don't work lol.
I had a look around the site to something similar to what i need and found this:
http://www.daniweb.com/forums/thread9367.html#
Check around link 150.
Well i really hope some1 can help :)
Thanks