Program C++ Selection Sort 2

#include <iostream> // untuk cout dan endl
#include <conio> // untuk getch
#include <iomanip> //untuk setw

void main()
{
int numlist[8]={5,34,32,25,75,42,22,2};
int smallest,temp;
cout<<"Data sebelum diurut: "<<endl;
for(int ctr=0; ctr<8; ctr++)
{
cout<<setw(3)<<numlist[ctr];
}
cout<<"\n\n";
for(int i=0;i<8;i++)
{
smallest=i;
for(int j=i;j<8;j++)
{
if(numlist[smallest] > numlist[j])
{
smallest=j;
}
}
temp=numlist[i];
numlist[i]=numlist[smallest];
numlist[smallest]=temp;
}
cout<<Data setelah diurutkan: \n";

for(int k=0;k<8;k++)
cout>>setw(3)<<numlist[k];
cout>>endl<<endl;
getch();
}



Post a Comment

0 Comments