#include <iostream.h>
#include <conio.h>
void tampilkan_larik(int data[], int n)
{
int i;
for (i=0;i<n;i++)
cout<<data[i]<<" ";
cout<<"\n";
}
void selection_sort (int data[], int n)
{
int posMin, posAwal, j, tmp;
for (posAwal=0;posAwal<n-1;posAwal++)
{
posMin=posAwal;
for (j=posAwal+1;j<n;j++)
if (data[posMin]>data[j])
posMin=j;
//tukarkan
tmp=data[posAwal];
data[posAwal]=data[posMin];
data[posMin]=tmp;
cout<<"hasil posAwal= "<<posAwal<<" : ";
tampilkan_larik(data,n);
}
}
int main()
{
int jum_data;
jum_data=8;
int i;
int data[]={25,57,48,37,12,92,80,33};
selection_sort(data, jum_data);
//hasil pengurutan
cout<<endl;
cout<<"Hasil pengurutan:\n";
tampilkan_larik(data,jum_data);
getch();
}
Jumat, 24 Juni 2011
program selection_sort
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar