answersLogoWhite

0

How you get a code of Radix sort?

Updated: 12/22/2022
User Avatar

Wiki User

12y ago

Best Answer

#include<stdio.h>

void radix(int a[],int n)

{

int i,j,k=1,l,temp,b[10][n],cnt;

int max=a[0],c=0;

for(i=0;i<n;i++)

if(a[i]>max)

max=a[i];

while(max%10)

{

c++;

max/=10;

}

for(i=0;i<10;i++)

for(j=0;j<n;j++)

b[i][j]=-999;

for(l=0;l<c;l++)

{

for(j=0;j<n;j++)

{

temp=(a[j]/k)%10;

b[temp][j]=a[j];

}

k=k*10; cnt=0;

for(i=0;i<10;i++)

for(j=0;j<n;j++)

if(b[i][j]!=-999)

a[cnt++]=b[i][j];

for(i=0;i<10;i++)

for(j=0;j<n;j++)

b[i][j]=-999;

}

}

main()

{

int i,n;

printf("Enter array capacity \t: ");

scanf("%d",&n);

int a[n];

for(i=0;i<n;i++)

a[i]=rand()%100;

printf("\nArray Before Sorting : ");

for(i=0;i<n;i++)

printf("%4d",a[i]);

radix(a,n);

printf("\n\nArray After Sorting : ");

for(i=0;i<n;i++)

printf("%4d",a[i]);

printf("\n");

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How you get a code of Radix sort?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a c plus plus program to sort a vector of strings using MSD radix sort?

The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector&lt;std::string&gt; vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}


Algorithm to convert a number representing radix r1 to r2?

algorithm to convert a number representing radix r1 to radix r2


How many algorithms are there for sorting purpose and what are they?

There are many sorting algorithms however there are only a small handful that we actually use: insertion sort (stable) is typically used for small sets while large data sets primarily use heapsort (unstable), merge sort (stable) or quicksort (unstable). Efficient implementations typically use a hybrid sort such as Timsort (stable) or introsort (unstable). The following lists all the documented algorithms currently listed in Wikipedia's "Sorting algorithm" page: Quicksort, merge sort, in-place merge sort, heapsort, insertion sort, introsort, selection sort, Timsort, cubesort, shell sort, bubble sort, binary tree sort, cycle sort, library sort, patience sorting, smoothsort, strand sort, tournament sort, cocktail sort, comb sort, gnome sort, unshuffle sort, Franceschini's sort, block sort, odd-even sort, pigeonhole sort, bucket sort (uniform keys), bucket sort (integer keys), counting sort, LSD radix sort, MSD radix sort, MSD radix sort in-place, spreadsort, burstsort, flashsort, postman sort bead sort, simple pancake sort, spaghetti sort, sorting network, bitonic sorter, bogo sort, stooge sort, Han's algorithm, Thorup's algorithm.


What is the time complexity of radix sort?

If the range of numbers is 1....n and the size of numbers is k(small no.) then the time complexity will be theta n log..


What is the space complexity of shell sort?

average case worst case LSD Radix sort O(n.k/s) O(n.k/s) MSD Radix sort O(n.k/s) O(n.k/s.2^s) n=no of items to be sorted k=size of each key s=chunk size used by implementation LSD=Least Significant Digit MSD=Most Significant Digit

Related questions

What is the pseudo code of radix sort in java?

:-P


Which of the following cannot be implemented efficiently in linear linked list 1 quicksort 2 radix sort 3 polynomials 4 insertion sort 5 binary search?

radix sort


How do you write a c plus plus program to sort a vector of strings using MSD radix sort?

The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector&lt;std::string&gt; vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}


Why is an excess-3 code is called an unweighted code?

here we can't convert to any radix system.only one way adding 3 creates decimal system. Later we need convert what we want, in remaining radix systems we have weight/radix which tells that to convert to particular system directly.


Can you use negative numbers in radix sort?

You'll have to make some modifications to the "standard" radix sort. You can add on a set value to make all the numbers positive, then sort with radix sort, then subtract the value off all of them at the end. This probably isn't the best all-round solution because if your numbers get very large (and large negative numbers), you may be unable to add on the set value to make all your values positive without having the problem of overflow. In this case you'd have to make a division - a section of negative numbers, and a section of of positive numbers. Sort both of them using radix sort, then reverse the negative numbers section and put the lists together (remembering to sort out the minus signs before sorting the negative numbers).


What is a thamnophis radix?

there is no such thing as a thamnophis radix


When was Radix jordii created?

Radix jordii was created in 2007.


When was Radix - novel - created?

Radix - novel - was created in 1981.


When was Radix - studio - created?

Radix - studio - was created in 1995.


When was Radix linae created?

Radix linae was created in 2007.


Algorithm to convert a number representing radix r1 to r2?

algorithm to convert a number representing radix r1 to radix r2


What is the ISBN of Radix novel?

The ISBN of &quot;Radix&quot; novel by A. A. Attanasio is 0553255378.