DFS :: Selection

#include<stdio.h>
void main()
{
int *iptr,size,k,temp;
ankur:
printf(“Enter the size of the array:”);
scanf(“%d”,&size);
if(size<1)
{
printf(“Invalid Size\nTry Again!!!!!\n”);
goto ankur;
}
else
{
iptr=new int[size];
for(int i=0;i<size;i++)
{
printf(“Enter element%d:”,i+1);
scanf(“%d”,&iptr[i]);
}
for(i=0;i<size-1;i++)
{
k=i;
for(int j=i+1;j<size;j++)
{
if(iptr[k]>iptr[j])
k=j;
}
if(k!=i)
{
temp=iptr[i];
iptr[i]=iptr[k];
iptr[k]=temp;
}
}
printf(“Selection Sorting of an Array is as follows:\n”);
for(i=0;i<size;i++)
printf(“%d\n”,iptr[i]);
}
}

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.