1 개요[ | ]
- 함수 rsort()
- 내림차순 정렬
- rsort([11,1,2,12]) → [12,11,2,1]
- rsort(['Banana','Orange','Apple','Mango']) → ['Orange','Mango','Banana','Apple']
2 Bash[ | ]

Bash
Copy
ARR=(11 1 12 2)
SORTED=`for VALUE in "${ARR[@]}"; do echo $VALUE; done | sort -rn`
echo ${SORTED[@]} # 12 11 2 1
Loading
3 C++[ | ]

C++
Copy
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> v = {11, 1, 12, 2};
sort(v.begin(), v.end(), [](int a, int b) -> bool { return a > b; });
for(int el: v) cout << el << ' '; // 12 11 2 1
}
Loading
4 Java[ | ]

Java
Copy
import java.util.Arrays;
import java.util.Collections;
public class App {
public static void main(String args[]) {
Integer arr[] = {11, 1, 2, 12};
Arrays.sort(arr, Collections.reverseOrder());
System.out.println(Arrays.toString(arr)); // [12, 11, 2, 1]
}
}
Loading
5 PHP[ | ]

PHP
Copy
$arr = [11, 1, 12, 2];
rsort($arr);
foreach($arr as $i) echo "$i "; // 12 11 2 1
Loading
6 Python[ | ]

Python
Copy
lst = ['Banana', 'Orange', 'Apple', 'Mango']
lst.sort(reverse=True)
print(lst) # ['Orange', 'Mango', 'Banana', 'Apple']
Loading
Python
Copy
lst = ['Banana', 'Orange', 'Apple', 'Mango']
lst.sort()
lst.reverse()
print(lst) # ['Orange', 'Mango', 'Banana', 'Apple']
Loading
7 Perl[ | ]
Perl
Copy
use Sort::Key qw(rsort);
my @lst = ('Banana', 'Orange', 'Apple', 'Mango');
@lst = rsort @lst;
print @lst;
# OrangeMangoBananaApple