Skip to content

Commit af5060e

Browse files
Sorting an Array using built in Sort function
1 parent e795410 commit af5060e

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
30 50 10 20 40

output.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
10 46 3.86
2-
2003576 2003136 3.86
1+
50 40 30 20 10

sort_array_using_sort_function.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
int a[n];
9+
for (int i = 0; i < n; i++)
10+
{
11+
cin >> a[i];
12+
}
13+
14+
// Sorting in Ascending Order
15+
sort(a, a + n);
16+
17+
// Sorting in Descending Order
18+
// sort(a, a + n, greater<int>());
19+
20+
for (int i = 0; i < n; i++)
21+
{
22+
cout << a[i] << " ";
23+
}
24+
return 0;
25+
}

sort_array_using_sort_function.exe

67.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)