Selection Sort
In selection sort we select an item i.e. minimum aur maximum and sort it by placing it in the first or last position.This process is repeated until the whole array is sorted. The time required is O(n^2).
#include<stdio.h>
#include<conio.h>
void SelectionSort(int *arr, int len){
int i,j,temp,min;
for(i=0;i<len-1;i++)
{
min = i;
for(j=i+1;j<len;j++)
{
if(arr[min]>arr[j])
{
min=j;
}
}
if(min != i)
{
temp = arr[i];
arr[i]=arr[min];
arr[min]=temp;
}
}
}
int main()
{
int arr[6]={4,5,2,8,6,3};
SelectionSort(arr,6);
for(int i=0;i<6;i++)
{
printf(" %d ",arr[i]);
}
getch();
return 0;
}
Download Program


