+ 8

How to sort an array ?

10th Nov 2018, 7:09 AM
Ankit Chaudhary
Ankit Chaudhary - avatar
5 Respuestas
+ 14
https://www.sololearn.com/learn/774/?ref=app
10th Nov 2018, 7:23 AM
Mert Yazıcı
Mert Yazıcı - avatar
+ 12
don't forget to write import statememt "import java.util.Arrays;" Arrays.sort(array_name); //to sort array directly //in java
10th Nov 2018, 2:33 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 8
That depends much on the language you are using. For the ones on your profile: Python: It is as simple as to call "sort" on your array (list) a = [4,2,3] a.sort() C++: You can use the sorting algorithms in the algorithm header: #include <algorithm> int a[] = {4,2,3}; sort(begin(a), end(a)); C: It is a little more complicated because you have to pass the comparison function along with it. There is a qsort algorithm in the stdlib header: #include <stdlib.h> // comparison function int cmp(void*x, void*y) { return *(int*)x - *(int*)y; } int a[] = {4,2,3}; qsort(a, 3, sizeof(int), cmp);
10th Nov 2018, 7:28 AM
Leif
Leif - avatar
+ 6
In Java: Arrays.sort(arr); In C#: Array.Sort(arr);
10th Nov 2018, 1:08 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar