top of page
Wave
Cactus%20Plant_edited.jpg

RADIX SORT

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a[50][50],b[50],top[50],n,i,j,k,l,len,pos;
    printf("Enter the highest length of the number: ");
    scanf("%d",&len);
    printf("\nHow many number you want to insert: ");
    scanf("%d",&n);
    printf("\n");
    for(i=0;i<n;i++)
    {
        printf("array[%d]= ",i+1);
        scanf("%d",&b[i]);
    }
    for(i=0;i<len;i++)
    {
        for(j=0;j<10;j++)
        {
            top[j]=(-1);
        }
        for(k=0;k<n;k++)
        {
            pos=(int)(b[k]/pow(10,i))%10;
            a[pos][++top[pos]]=b[k];
        }
        l=(-1);
        for(j=0;j<10;j++)
        {
            for(k=0;k<=top[j];k++)
            {
                b[++l]=a[j][k];
            }
        }
    }
    printf("\nThe array after radix sort:\n");
    for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }
    return 1;
}

Subscribe Form

Thanks for submitting!

  • Facebook
  • YouTube
  • Instagram
  • Twitter

©2020 by Abhisek Midya ( A18 )

bottom of page