Merge pull request #12 from Roshaen/main

Added selection sorting algorithm
pull/13/head
Ming Tsai 2021-01-17 08:07:25 -04:00 committed by GitHub
commit 31ea320988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
# include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{ // length of array
cout<<"Enter the length of array"<<endl;
int n,temp;
cin>>n;
int arr[n];
// Getting elements of array
cout<<"Enter the elements of array"<<endl;
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
for (int i = 0; i < n; i++)
{
for(int j = i; j<n; j++)
{ // comparing elements of array
if(arr[j]<arr[i])
{
temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
return 0;
}