What is Selection Sort ?
Selection sort is a simple comparison-based sorting algorithm that works by dividing the input list into two parts: the sorted part and the unsorted part. The algorithm repeatedly finds the minimum (or maximum, depending on the sorting order) element from the unsorted part and moves it to the end of the sorted part. This process continues until the entire list is sorted.//selection Sort
#include<stdio.h>
#define SIZE 6
int main(){
int arr[SIZE]={12,3,2,5,1,10};
int i,j,min;
for(i=0; <SIZE-1;i++){
min=i;
for(j = i+1;j < SIZE;j++){
if(arr[min]>arr[j]{
min=j;
}
}
int temp=arr[min];
arr[min]=arr[i];
arr[i]=temp;
}
for(i=0;i < SIZE;i++){
printf("%d",arr[i]);
}
printf("\n");
return 0;
}


Post a Comment