2020-05-30 07:26:30 +08:00
|
|
|
// Selection Sort
|
2016-07-16 19:08:05 +08:00
|
|
|
|
2019-08-21 10:10:08 +08:00
|
|
|
#include <iostream>
|
2016-07-16 19:08:05 +08:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2020-05-30 07:26:30 +08:00
|
|
|
int Array[6];
|
|
|
|
cout << "\nEnter any 6 Numbers for Unsorted Array : ";
|
2019-08-21 10:10:08 +08:00
|
|
|
|
2020-05-30 07:26:30 +08:00
|
|
|
// Input
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
cin >> Array[i];
|
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
|
2020-05-30 07:26:30 +08:00
|
|
|
// Selection Sorting
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
int min = i;
|
|
|
|
for (int j = i + 1; j < 6; j++)
|
|
|
|
{
|
|
|
|
if (Array[j] < Array[min])
|
|
|
|
{
|
|
|
|
min = j; // Finding the smallest number in Array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int temp = Array[i];
|
|
|
|
Array[i] = Array[min];
|
|
|
|
Array[min] = temp;
|
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
|
2020-05-30 07:26:30 +08:00
|
|
|
// Output
|
|
|
|
cout << "\nSorted Array : ";
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
cout << Array[i] << "\t";
|
|
|
|
}
|
2016-07-16 19:08:05 +08:00
|
|
|
}
|