Sunday, 13 March 2016

C++ Code For Selection Sort

Share & Comment
Selection sort example

The selection sort is the algorithm which is used to sort the unsorted array.
This is the easiest way to sort the unsorted array through selection sort. here is the code for selection sort in c++.


------------------------------------------------------------------------------------------------------------------

// Selection Sort-

#include <iostream>
#include <conio.h>
using namespace std;
void selectionsort (int arry[], int size){
int min=0;
int ismin=false;

for(int i=0;i<size;i++){
int min=i;
ismin=false;
for(int j=i+1;j<size;j++){
if(arry[j]<arry[min]){
min=j;
ismin=true;
   }
}
if(ismin=true){
int temp=0;
temp=arry[i];
arry[i]=arry[min];
arry[min]=temp;
}
}
}
int main(){
int arry[5]={41,25,36,96,85};
selectionsort(arry,5);
for(int i=0;i<5;i++){
cout<<arry[i];
cout<<" ";
}
getch();
}

//end code ///////////////////////////////////////////////////////////////////////


Tags: , ,

Written by

We are the second largest blogger templates author, providing you the most excellent and splendid themes for blogger cms. Our themes are highly professional and seo Optimized.

0 comments:

Post a Comment

 
@2014 | Designed by CIITCLUSTER