Skip to content

Instantly share code, notes, and snippets.

@zainulhasan
Created August 3, 2015 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zainulhasan/d0ed6960102f49af8fd1 to your computer and use it in GitHub Desktop.
Save zainulhasan/d0ed6960102f49af8fd1 to your computer and use it in GitHub Desktop.
/******************************
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