showing results for - "sort descending array"
Ana Sofia
11 May 2020
1function sortEggsInNest(a, b) {
2  return a > b ? -1 : b > a ? 1 : 0;
3}
Amadou
25 Sep 2020
1Array -- Sort Descending
2Write a return method that can sort an int array in descending order without using the sort method of the Arrays class
3Ex:  int[] arr = {10,20,7, 8, 90};
4                 arr = Sort(arr);  ==>  {90, 20, 10, 8, 7};
5 
6Solution 1:
7public static void main(String[] args) {
8    ArrayList<Integer> arr = new ArrayList<Integer>(5);
9    arr.add(12);arr.add(4);arr.add(6);arr.add(8);arr.add(20);
10    System.out.println(findMin(arr));
11public static int[] Sort(int[] a) {
12ArrayList<Integer> list=new ArrayList<Integer>();
13for(int each: a)
14list.add(each);
15 
16for(int i=0; i < a.length; i++) {
17a[i] = findMax(list);
18list.remove(Integer.valueOf(a[i]));
19}
20return a;
21}
22 
23public static int findMax(ArrayList<Integer> a) {
24int max=Integer.MIN_VALUE;
25for(int each: a)
26max = Math.max(max, each);
27return max;
28}
29 
30Solution 2:
31public static void main(String[] args) {
32    ArrayList<Integer> arr = new ArrayList<Integer>(5);
33    arr.add(12);arr.add(4);arr.add(6);arr.add(8);arr.add(20);
34    System.out.println(findMin(arr));
35
36public static void SortingArrayDesc(int[] arr) {
37ArrayList<Integer> list = new ArrayList();
38for(int each: arr) {
39list.add(each);
40}
41for (int i = 0; i < list.size(); i++) {
42            for (int j = 0; j < list.size(); j++) {
43            if (list.get(i) > list.get(j)) {
44                    Integer temp = list.get(i);
45                    list.set(i, list.get(j));
46                    list.set(j, temp);
47            }
48              }
49}
50for(int i=0; i < list.size(); i++) {
51arr[i] = list.get(i);
52}
53}
queries leading to this page
sort array in descending order javascripthow to print array in descending order javascriptdescending order sort jsprint descending order javascriptdescending order using function javascriptmdn js sort descendingsort desc jsarrays sort descendingthe function descendingsortarrayort descending jsarray sort in javascript descendingarray descending order in jsturn array to descending order javascriptsort array descending sort descending jsarray orderby descendingjs descending sortjs sort reversedescending order function in javascriptdescending sort arraydescending order array javascriptjs sort descendingsort array descending jsjavascript sort reverse orderdescending order of array using javascript example codesort 28 29 reverse 28 29 javascripthow to sort in descending jsorder desc javascriptjs sort array descendingjavascript sort array descending and asending ordersorting list in javascript descendinghow to sort an array in javascript in descending order without sortjs sort in reverse ordersort in descending order nodejssort decreasing javascriptsort array in descending order jsjavascript reverse sort arrayjavascript sort array in reverse ordersort an array in descending ordersort array in descendingjavascript array sort descending orderjs array sort descendingjavascript sort array descendingsort in descending order jsjavascript sort ascending and descending methodsarray prototype sort descendingorder array javascript descendinghow to sort an array in descending order in javascriptorder descnding array jssort array in ascending and descending order in javascriptsort descending in jsjavascript sort in descending orderarrays sort descendingreverse sort in javascriptdescending order in javascriptsort array in reverse orderarrange array in descending order javascripthow to sort array in descending order in javascriptjs sort reverse orderhow to sort an array in descending order javascriptdescending order javascriptsort an array with descending and ascending jsjavascript sort array descendingsort ascending descending javascriptarray in descending order jsjavascript descending sortarray descending orderfunction descendingorder jshow to make an array in descending order in javascriptjavascript order by created at descendingsort in descending in jsarray sort reversesort js descendingjavascript array descending orderput array in descending order javascriptnode sort array descendingsort array value descending javascriptjavascript array sort descendingjavascript descending order sortsort in descending jsjavascript sort reversesort descending jssort array js descendingjavascript sort array reverse orderjs sort array descending orderdescending order arraysort javascript descending by valuesort an array descending ordersort the array in descending orderdescending order sorting method in javascrupthow to reverse sort jsarray sort 28 29 function descending osort in descending order in jssort with reverse jsreverse sort order in array javascriptjavascript array desc ordernodejs sort descendinghow to sort in descending order in javascriptjs order descendingarray sort descending javascripthow to print descending order in javascriptarray descending order javascriptsort descending javascript requestarray sort reverse javascripthow to sort descending in javascriptsort reverce javascriptnodejs sort array descendingreverse sort jsdesc sort javascriptarray sort descending javascriptsort array in descending order id javascriptjavascript array sort in reversesort descending js sortsort desc in javascriptjs sort reverse sortarray descending javascriptsorting code in descending javascriptsort array descending in javascriptsort by descending jsjs reverse sortsort in descending order in js htmlsort function for ascending and descending order in javascripthow to sort array in reverse order jsjs array descending orderarray sort reverse jsdescending order jsjs array sort descdescending order in jsdescending sort javascripthow to sort array in descending orderorder array descjavascript array sort ascending descendinghow to sort array in descendingjs dore descendingsort descending arraysort array by descending javascriptsort descending order javascriptjavascript sort function descendingdescending order array javascript without sort function javascript sort by descendingjs array sort reversejs order by descendingsort javascript descendingreverse sort function in jssort array javascript descendingsort algorithm descending order javascriptdescending order javascript array withoutjavascript sort array by descending valuereverse sort javascriptsort array in reverse order javascriptsort array descending order javascriptjavascript array sort reversedescending order array sortdescending order javascript arrayjavascript sort in reverse orderjs descendingarray sort descendingsorting in descending order jssort javascript reverse orderjs sorting descendingjs sort by descendinghow to code descending order in javascriptsort descending in javascriptsort reverse javascriptjs array sort descending javscript without using sort methodsort descending javascriptsort array reversejs sort descjavascript undo sortjs array sort descending javscriptarray sort in descending order javascriptsort reverse jssort arrays descendinghow to sort array descanding ordersort array reverse jsthe function descending sort arraysort then reverse jsarray descending order in javascriptjavascript sort array by value descendingjavascript ascending and descendingundo sort jses6 sort array based on array descending order javascript array sort descending idhow to sort in descending order in java scriptsort array descending javascriptsort an array in descending order javascriptjavascript reverse sortsoert array descendingsort in descending order javascriptjavascript sortby descendingsort the array descending orderhow to sort in descending order in jsdescending sort in javascriptsort in reverse order using javascriptsort desc javascriptsort reverse order javascripthow to display data in descending order in javascriptsort array in descending orderhow to sort descending javascriptsort array in descending javascriptdescending order function javascriptjavascript sort descendingjavascript descending ordersort descending array