sorting in descending order

Solutions on MaxInterview for sorting in descending order by the best coders in the world

showing results for - "sorting in descending order"
Alessio
31 Sep 2020
1ArrayList -- sorting in descending order
2Write a method that can sort the ArrayList in descending order
3without using the sort method
4 
5Solution:
6public static void SortingArrayListDesc(List<Integer> list) {
7        for (int i = 0; i < list.size(); i++) {
8        for (int j = 0; j < list.size(); j++) {
9        if (list.get(i) > list.get(j)) {
10                    Integer temp = list.get(i);
11                    list.set(i, list.get(j));
12                    list.set(j, temp);
13                    }
14            }
15   }
16    }
Allison
27 Jan 2018
1function solution(n) {
2    return parseInt(n.toString().split('').sort((val1,val2) => val2-val1).join(''));
3}
4
5