0% found this document useful (0 votes)
7 views1 page

Selectionsort

Selection sort

Uploaded by

fanfare642
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Selectionsort

Selection sort

Uploaded by

fanfare642
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream>

using namespace std;


class selectionsort
{
int a[100],n,j,l,temp,loc,min;
public:
int in();
int out();
selectionsort()
{
min=a[0];
}
};
int main()
{
selectionsort ss;
ss.in();
ss.out();
}
int selectionsort::in()
{
cout<<"enter the number of elements:";
cin>>n;
cout<<"\n enter the elements\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
return 0;
}
int selectionsort::out()
{
for(int i=0;i<n-1;i++)
{
min=a[i];
loc=i;
for(j=i+1;i<=n-1;j++)
{
if(a[j]<min)
{
min=a[j];
loc=j;
}
}
if(loc!=1)
{
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
}
cout<<"\n sorted list is as follows\n";
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}

You might also like