Program Selection Sort |
/*filename = Program Selection Sort */
/*Oleh : fk_seven */
/*Date : 18 Agustus 2011 */
#include <iostream.h>
#include <conio.h>
void tampil(int data[], int n);
void seleksi(int data[], int n);
main()
{
const jml_data=10;
int data[]={40, 75, 90, 85, 15, 35, 55, 25, 10, 60};
cout<<"Data sebelum diurutkan"<<endl;
tampil(data, jml_data);
cout<<endl;
cout<<"Proses Pengurutan Ascending"<<endl;
seleksi(data, jml_data);
cout<<endl;
cout<<"Hasil Pengurutan Ascending"<<endl;
tampil(data, jml_data);
cout<<endl;
getch();
}
void tampil(int data[], int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
void seleksi(int data[], int n)
{
int min, awal, j, tmp;
for(awal=0;awal<n-1;awal++)
{
min=awal;
for(j=awal+1;j<n;j++)
{
if(data[min]>data[j])
{
min=j;
}
}
tmp=data[awal];
data[awal]=data[min];
data[min]=tmp;
cout<<"Hasil Awal = "<<awal+1<<" : ";
tampil(data, n);
}
}
0 komentar:
Posting Komentar