desislava_topuzakova

08. Custom List Sorter -> Sorter.java

Oct 18th, 2020
1,978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. package CustomListSorter_08;
  2.  
  3. class Sorter<T extends Comparable<T>> {
  4.  
  5.     static void sort(CustomList customList) {
  6.         for (int i = 0; i < customList.size(); i++) {
  7.             String  element = (String) customList.get(i);
  8.             for (int j = i + 1; j < customList.size(); j++) {
  9.                 String elementToSwap = (String) customList.get(j);
  10.                 if (element.compareTo(elementToSwap) > 0) {
  11.                     customList.swap(i, j);
  12.                 }
  13.             }
  14.         }
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment