-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSORT2.cpp
More file actions
35 lines (35 loc) · 771 Bytes
/
Copy pathSORT2.cpp
File metadata and controls
35 lines (35 loc) · 771 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
#include <iostream>
using namespace std;
void SelectionSort(int arr[], int n)
{
int minindex, temp = 0;
for (int i = 0; i < n - 1; i++)
{
minindex = i;
for (int j = i + 1; j < n; j++)
{
if (arr[j] < arr[minindex])
minindex = j;
}
temp = arr[i];
arr[i] = arr[minindex];
arr[minindex] = temp;
if (i == 1)
{
for (int k = 0; k < n; k++)
cout << arr[k] << " ";
}
}
} //author anas khan
int main()
{
int n, arr[20];
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
SelectionSort(arr, n);
cout << "\nSorted Array:";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}