Skip to content

Commit 2990cb0

Browse files
Selection sort using C++ Done
1 parent b50178b commit 2990cb0

8 files changed

+37
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"E. Max","group":"Codeforces - Sheet #2 (Loops)","url":"https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/E","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"5\n1 8 5 7 5\n","output":"8\n","id":1718697543652}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"EMax"}},"batch":{"id":"fce6e903-a7aa-43a4-8da5-d35279de29d5","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\2. Introduction to C++\\E_Max.cpp"}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"H. Sorting","group":"Codeforces - Sheet #3 (Arrays)","url":"https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/H","interactive":false,"memoryLimit":64,"timeLimit":1000,"tests":[{"input":"3\n3 1 2\n","output":"1 2 3\n","id":1718696982454},{"input":"4\n5 2 7 3\n","output":"2 3 5 7\n","id":1718696982520}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"HSorting"}},"batch":{"id":"271dabfb-f1c6-4ea3-b328-2236e41faba0","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\2. Introduction to C++\\H_Sorting.cpp"}
1+
{"name":"H. Sorting","group":"Codeforces - Sheet #3 (Arrays)","url":"https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/H","interactive":false,"memoryLimit":64,"timeLimit":1000,"tests":[{"input":"3\n3 1 2\n","output":"1 2 3\n","id":1718696982454},{"id":1718696982520,"input":"4\n5 2 7 3\n","output":"2 3 5 7\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"HSorting"}},"batch":{"id":"271dabfb-f1c6-4ea3-b328-2236e41faba0","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\2. Introduction to C++\\H_Sorting.cpp"}

E_Max.cpp

Whitespace-only changes.

H_Sorting.bin

51.1 KB
Binary file not shown.

H_Sorting.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 the array using selection sort
15+
for (int i = 0; i < n - 1; i++)
16+
{
17+
for (int j = i + 1; j < n; j++)
18+
{
19+
if (a[i] >= a[j])
20+
{
21+
swap(a[i], a[j]);
22+
}
23+
}
24+
}
25+
26+
for (int i = 0; i < n; i++)
27+
{
28+
cout << a[i] << " ";
29+
}
30+
31+
return 0;
32+
}

H_Sorting.exe

51.1 KB
Binary file not shown.

input.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
10 20 30 40 50
1+
5
2+
2 2 1 7 5

output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10 20 30 40 50
1+
1 2 2 5 7

0 commit comments

Comments
 (0)