Created
August 3, 2015 05:32
-
-
Save zainulhasan/d0ed6960102f49af8fd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************** | |
selectionSort.cpp | |
Auther:Syed Zain Ul hasan | |
*****************************/ | |
#include <iostream> | |
using namespace std; | |
int selection_sort(int arr[],int n){ | |
for(int i=0;i<n;i++) | |
{ | |
//first find the minimum element's index | |
//then swap that index with i ;) | |
int min=i; | |
for(int j=i+1;j<n;j++) | |
if(arr[min]>arr[j]) | |
min=j; | |
//swap | |
swap(arr[i],arr[min]); | |
} | |
} | |
int main() { | |
int arr[10]={5,8,79,9,87,98,7,2,5,4}; | |
selection_sort(arr,10);//sorting | |
//now print array | |
for(int i=0;i<10;i++) | |
cout<<arr[i]<<" "; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment