# radix sort - {front[y]=p else rear[y>next=p rear[y]=p...

This preview shows pages 1–4. Sign up to view the full content.

#include<stdio.h> #include<conio.h> /* RISHI AGARWAL             RADIX SORT    ROLL NO 02    SE CMPN A */ #define max 10 int x[max]; struct node {  int data;  struct node *next; }; struct node *front[10],*rear[10],*start,*prev,*p; void display(int a[],int n) {  int i;  printf("\nLIST\n");  for(i=0;i<n;i++)  printf("%d ",a[i]); } int largest(int x[],int n) {  int q,i,t;  q=x[0];  for(i=1;i<n;i++)  {   if(q<x[i])   q=x[i];  }  t=q;  i=0;  while(t>0)  {   t=t/10;   i++;  }  return i; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
void radixsort(int x[],int n) {  int i,j,k,exp,l,y,z,p1=0,m;  start=NULL;  m=largest(x,n); for(i=0;i<n;i++)  {   p=(struct node *)malloc(sizeof(struct node));   p->data=x[i];   p->next=NULL;   if(start==NULL)   start=p;   else   {    prev->next=p;   }   prev=p;  } for(i=1;i<=m;i++)  {   for(j=0;j<10;j++)   {    front[j]=NULL;    rear[j]=NULL;   }   exp=1;   for(k=1;k<i;k++)   exp=exp*10;   p=start;   while(p!=NULL)   {    l=p->data;    y=(l/exp)%10;    if(front[y]==NULL)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: {front[y]=p;} else { rear[y]->next=p; } rear[y]=p; p=p->next; } start=NULL; for(k=0;k<10;k++) { if(front[k]!=NULL) { if(start==NULL) start=front[k]; else { rear[p1]->next=front[k]; } rear[k]->next=NULL; p1=k; } } } p=start; for(z=0;z<n;z++) { x[z]=p->data; p=p->next; } } void main() { int n,i; clrscr(); printf("Enter the no of data:"); scanf("%d",&n); printf("Enter the nos"); for(i=0;i<n;i++) scanf("%d",&x[i]); //Displaying List display(x,n); //Radix Sort radixsort(x,n); //Displaying Sorted List display(x,n); getch(); } /* OUTPUT: Enter the no of data:10 Enter the nos100 80 90 70 50 60 10 40 30 20 LIST 100 80 90 70 50 60 10 40 30 20 LIST 10 20 30 40 50 60 70 80 90 100 */...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern