#Bubblesort with arraylists

12 messages · Page 1 of 1 (latest)

undone flower
#

Im trying to code a bubblesort with arraylists, but struggling with the temp part, im not really sure how to move forward from this point.

public static void bubbleSort(ArrayList<Course> a) {
Course temp;
for (int b = 0; b < list.size(); b++) {
for(int i = 1; i < list.size() - b - 1; i++) {
if (a.get(i - 1).compareTo(a.get(i) > 0) {
temp = list.get(i);
list.set(i, list.get(i-1))
list.set((i-1), temp))
}
}
}

}

balmy sunBOT
#

This post has been reserved for your question.

Hey @undone flower! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

balmy sunBOT
crude hamlet
#

you forgot a ) after .get(i)

undone flower
#

Okay so I got it to run, but it doesnt actually print anything now

limber knollBOT
#

I wrote public static void printbubble(ArrayList<Course> a) { for(Course course : a) System.out.println(course); }

to print it but it doesnt print

This message has been formatted automatically. You can disable this using /preferences.

undone flower
#

it runs but doesnt print

crude hamlet
#

are you using printbubble anywhere?

undone flower
#

oh i got it

#

i was missing actually calling the method

#

i missed the printbubble(list); at the top lmao