USING Selection SORT ARRANGE NUMBERS IN ASCENDING ORDER. Simple  C program selsction sort AnmolViidya.blogspot.com Sorting is...

Selection Sort : C program

USING Selection SORT ARRANGE NUMBERS IN ASCENDING ORDER.


Simple C program


Selection Sort : C program
selsction sort
AnmolViidya.blogspot.com

Sorting is the arrangement of data in the required manner. In this blog we will be discussing about one such type that is Selection sort and here we have given a simple c program for the explanation.Such type of questions can be ask in rtmnu Nagpur university cse 3rd sem question papers.Also in last of the blog we have given link to download rtmnu cse 3rd sem question papers.

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.

#include<stdio.h>
int main(){
int a[]={12,23,34,45,34,35,56,970,73};
//selection sort
/*
int n=(sizeof(a)/sizeof(int));
int i,j,temp,min;
for(i=0;i<n-1;i++)
{
    for(j=i+1;j<n;j++)
    {
        min=i;
        if(a[j]<a[min])
        {
            min=j;
        }
    }
    temp=a[i];
    a[i]=a[min];
    a[min]=temp;
}
for(i=0;i<n;i++)
    printf("%d\t",a[i]);
return 0;
}



0 comments: