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