Slide # 1

Slide # 1

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts Read More

Slide # 2

Slide # 2

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts Read More

Slide # 3

Slide # 3

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts Read More

Slide # 4

Slide # 4

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts Read More

Slide # 5

Slide # 5

Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts Read More

Kamis, 05 Maret 2015

Program Radix Sort

#include <stdio.h>
#define MAX 1000
#define SHOWPASS

void print(int *a,int n)
{
    int i;
    for(i=0;i<n;i++)
    printf("%d\t",a[i]);
}

void radixsort(int *a,int n)
{
    int i,b[MAX],m=0,exp=1;
    for(i=0;i<n;i++)
    {
        if(a[i]>m)
        m=a[i];
    }

    while(m/exp>0)
    {
    int bucket[10]={0};
        for(i=0;i<n;i++)
                 bucket[a[i]/exp%10]++;
                 for(i=1;i<10;i++)
                bucket[i]+=bucket[i-1];
                for(i=n-1;i>=0;i--)
                    b[--bucket[a[i]/exp%10]]=a[i];
                    for(i=0;i<n;i++)
                             a[i]=b[i];
                        exp*=10;

#ifdef SHOWPASS
    printf("\nBaris ke-%i  : ");
    print(a,n);
#endif
    }
}


int main()
{
    int arr[50];
    int i,n;

    printf("Masukkan Berapa Banyak Element Array  : ",MAX);
    scanf("%d",&n);
     for(i=0; i<n; i++)
     {

                 printf("masukkan data ke-%i =", i+1);
                 scanf("%i",&arr[i]);

     }

     printf("\nData  : ");
    print(&arr[0],n);

    radixsort(&arr[0],n);

    printf("\nUrutan : ");
    print(&arr[0],n);
    printf("\n");

    return 0;
}