Kode Program Bubble Sort Tipe data Char sederhana
BUBBLE SORT CHARACTER
#include
#include
void main()
{
int i,j;
char huruf[10],tukar;
int jumlah;
printf("Masukkan
jumlah huruf = ");
scanf("%d",&jumlah);
//memasukkan angka
for (i=0;i
{
printf("Masukkan
huruf ke%d = ",i+1);
scanf("%s",&huruf[i]);
}
printf("Indeks = ");
for(i=0;i
{
printf("%d ",i);
//menampilkan ketika belum
diurutkan
printf("\nData = ");
for (i=0;i
{
printf("%c ",huruf[i]);
}
for (i=0;i
{
for(j=i;j
{
if(huruf[i]>huruf[j])
{
tukar=huruf[i];
huruf[i]=huruf[j];
huruf[j]=tukar;
}
}
}
printf("\nAscending =
");
for(i=0;i
{
printf("%c ",huruf[i]);
}
for(i=0;i
{
for(j=i;j
{
if(huruf[j]>huruf[i])
{
tukar=huruf[j];
huruf[j]=huruf[i];
huruf[i]=tukar;
}
}
}
printf("\nDescending = ");
for(i=0;i
{
printf("%c ",huruf[i]);
}
getch();
}
0 komentar:
Posting Komentar