SHARE
TWEET

sorte

a guest May 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static <E extends Comparable<E>> Collection<E> sortList (Collection<E> list) {
  2.        
  3.         if (list.isEmpty())
  4.             return null;
  5.        
  6.         if (list.size() == 1)
  7.             return list;
  8.        
  9.         Iterator<E> itr = (Itr<E>) list.iterator();
  10.         ArrayList<E> arrayList = new ArrayList<>();
  11.         E temp;
  12.        
  13.         while(itr.hasNext()) {
  14.             arrayList.add(itr.next());
  15.         }
  16.        
  17.         list.clear();
  18.        
  19.         // Bubble Sort
  20.        
  21.         for (int i = 0; i < arrayList.size() - 1; i++)
  22.             for (int j = 0; j < arrayList.size() - 1 - i; j++) {
  23.                 if (arrayList.get(j).compareTo(arrayList.get(j+1)) > 0) {
  24.                     temp = arrayList.get(j);
  25.                     arrayList.set(j, arrayList.get(j+1));
  26.                     arrayList.set(j+1, temp);
  27.                 }
  28.             }
  29.        
  30.         list.addAll(arrayList);
  31.        
  32.         return list;   
  33.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top