Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Algorithm {
- void sort(Comparable[] list);
- }
- // A class for bubble sort
- public static class BubbleSort implements Algorithm {
- @Override
- public void sort(Comparable[] list) {
- int n = list.length;
- for (int i = 0; i < n - 1; i++) {
- for (int j = 0; j < n - i - 1; j++) {
- if (list[j].compareTo(list[j + 1]) > 0) {
- Comparable temp = list[j];
- list[j] = list[j + 1];
- list[j + 1] = temp;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement