mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Selection Sort
This commit is contained in:
parent
11e42c9f43
commit
d8853ff4ab
39
SelectionSort.cpp
Normal file
39
SelectionSort.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
//Selection Sort
|
||||
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int Array[6];
|
||||
cout<<"\nEnter any 6 Numbers for Unsorted Array : ";
|
||||
|
||||
//Input
|
||||
for(int i=0; i<6; i++)
|
||||
{
|
||||
cin>>Array[i];
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
//Output
|
||||
cout<<"\nSorted Array : ";
|
||||
for(int i=0; i<6; i++)
|
||||
{
|
||||
cout<<Array[i]<<"\t";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user