Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <E extends Comparable<E>> Collection<E> sortList (Collection<E> list) {
- if (list.isEmpty())
- return null;
- if (list.size() == 1)
- return list;
- Iterator<E> itr = (Itr<E>) list.iterator();
- ArrayList<E> arrayList = new ArrayList<>();
- E temp;
- while(itr.hasNext()) {
- arrayList.add(itr.next());
- }
- list.clear();
- // Bubble Sort
- for (int i = 0; i < arrayList.size() - 1; i++)
- for (int j = 0; j < arrayList.size() - 1 - i; j++) {
- if (arrayList.get(j).compareTo(arrayList.get(j+1)) > 0) {
- temp = arrayList.get(j);
- arrayList.set(j, arrayList.get(j+1));
- arrayList.set(j+1, temp);
- }
- }
- list.addAll(arrayList);
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement