Write a algorithm to accept 5 number and sort it in the ascending order using selection sort
#include<iostream.h>
#include<conio.h>
class selectionsort
{
Int a[100], n, i, j, temp, loc, min ;
public: void in( ) ;
void out( ) ;
selectionsort( )
{
Min = a[0] ;
}
};
void main( )
{
clrscr( ) ;
selectionsort ss ;
ss.in( ) ;
ss.out( ) ;
getch( );
}
void selectionsort::in( )
{
cout<<”enter the elements to the array: “ <<endl ;
for( i = 0; i<5; i++)
{
cin>>a[i] ;
}
voidselectionsort::out( )
{
for(i=0 ; i<5; i++)
{
min = a[i] ;
loc = i ;
for( j = i + 1; j<5; j++)
{
if( a[j]<min)
{
min = a[j] ;
loc = j ;
}
if( loc!= 1)
{
temp = a[i] ;
a[i] = a[loc] ;
a[loc] = temp ;
}
cout<<”The number after selection sorting are:” ;
for(i=0 ; i<5; i++)
{
cout<<endl<<a[i] ;
}
}
is my answer correct guy's need help on this tanx a lot