Professional Documents
Culture Documents
SELECTION SORT
Oleh :
Gusti Ayu Diah Kartika Dewi
(1205021002/IIIA)
(1205021008/IIIA)
(1205021015/IIIA)
(1205021019/IIIA)
//Input data
clrscr();
a[1] = 4;
a[2] = 8;
a[3] = 5;
a[4] = 9;
a[5] = 6;
a[6] = 2;
a[7] = 7;
a[8] = 5;
a[9] = 9;
a[10] = 5;
//Selection sort
clrscr();
for (i=1; i<=10-1; i++){
m=i;
for (c=i+1; c<=10; c++){
if (a[c] > a[m])
m = c;
}
temp = a[i];
a[i] = a[m];
a[m] = temp;
}
//Hasilnya
cout << "Sebelum di urut : 4 8 5 9 6 2 7 5 9 5\n\n";
cout << "Jadi Hasilnya : ";
for (i=1; i<=10; i++)
cout << a[i] << " ";
getch();
}
Hasil Program