radix sort - {front[y]=p;} else {...

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

View Full Document Right Arrow Icon
#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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
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]-&gt;next=p; } rear[y]=p; p=p-&gt;next; } start=NULL; for(k=0;k&lt;10;k++) { if(front[k]!=NULL) { if(start==NULL) start=front[k]; else { rear[p1]-&gt;next=front[k]; } rear[k]-&gt;next=NULL; p1=k; } } } p=start; for(z=0;z&lt;n;z++) { x[z]=p-&gt;data; p=p-&gt;next; } } void main() { int n,i; clrscr(); printf(&quot;Enter the no of data:&quot;); scanf(&quot;%d&quot;,&amp;n); printf(&quot;Enter the nos&quot;); for(i=0;i&lt;n;i++) scanf(&quot;%d&quot;,&amp;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

Page1 / 4

radix sort - {front[y]=p;} else {...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online