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();
}
0 comments:
Post a Comment