forked from fineanmol/Hacktoberfest2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.cpp
More file actions
44 lines (40 loc) · 757 Bytes
/
selection.cpp
File metadata and controls
44 lines (40 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
void display(vector<int> A, int n)
{
cout << endl;
for (auto i : A)
cout << i << " ";
}
void S_S(vector<int> &A, int n)
{
for (int i = 0; i < n - 1; i++)
{
int min = A[i];
int pos = i;
for (int j = i + 1; j < n; j++)
{
if (A[j] < min)
{
min = A[j];
pos = j;
}
}
swap(A[i], A[pos]);
}
}
int main()
{
vector<int> V;
int ch, n;
cout << "size: ";
cin >> n;
cout << "ENTER ARRY: ";
for (int i = 0; i < n; i++)
{
cin >> ch;
V.push_back(ch);
}
S_S(V, n);
display(V, n);
}