Question: How to implement a bubble sort algorithm to sort an ArrayList of candy bars by weight in descending order? I have to edit this method.

How to implement a bubble sort algorithm to sort an ArrayList of candy bars by weight in descending order?

I have to edit this method.

public static void bubbleSort(ArrayList list) { //code goes here }

I don't know how to do this. I know I'd have to use a for loop for it which would go through the array list and swapping the weights by order one by one which would also require a temp variable, but I need help starting it. I need the candy bars listed in order by weight in descending order.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!