radix sort program in c++

#include<iostream.h>
int i=0,b[10];
struct node{int data;
node *next;
}*a[10];


void addend(node *l,int p1)
{
node *t;node *u6;u6=l;
t=new node;
t->data=p1;
t->next=NULL;
while(l!=NULL)
{if(l->next!=NULL)
{l=l->next;}
else
if(l->next==NULL)
{l->next=t;
l=u6;
break;
}
}}


int delbeg(node *l)
{
node *u;
if(l->next!=NULL){u=l->next;
l->next=l->next->next;
return u->data;
}}
int power(int s,int u2)
{int product=1;
if(u2==0)
{return 1;}
else
{for(int k5=u2;k5>0;k5--)
product=product*s;
return product;}}


main()
{int count=0;int h,g;int m1=0;int z;int m2=0,n1,n2;int r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;cout<<"enter no of numbers and max digits"<<endl;
cin>>n1>>n2;
for(int j=0;j<n1;j++)
{cout<<"enter the numbers to sort"
cin>>b[j];}
for(int k=0;k<10;k++)
{a[k]=new node;
a[k]->data=k;
a[k]->next=NULL;}
while(count !=n2)
{for(m1=0;m1<n1;m1++)
{z=b[m1]/power(10,m2);
z=z%10;
switch(z)
{case 0:addend(a[0],b[m1]);r1++;break;
case 1:addend(a[1],b[m1]);r2++;break;
case 2:addend(a[2],b[m1]);r3++;break;
case 3:addend(a[3],b[m1]);r4++;break;
case 4:addend(a[4],b[m1]);r5++;break;
case 5:addend(a[5],b[m1]);r6++;break;
case 6:addend(a[6],b[m1]);r7++;break;
case 7:addend(a[7],b[m1]);r8++;break;
case 8:addend(a[8],b[m1]);r9++;break;
case 9:addend(a[9],b[m1]);r10++;break;
default:cout<<"no";break;
}}
for(int x11=0;x11<r1;x11++)
{b[g]=delbeg(a[0]);g++;
}for(int x1=0;x1<r2;x1++)
{b[g]=delbeg(a[1]);g++;}
for(int x2=0;x2<r3;x2++)
{b[g]=delbeg(a[2]);g++;}
for(int x3=0;x3<r4;x3++)
{b[g]=delbeg(a[3]);g++;}
for(int x4=0;x4<r5;x4++)
{b[g]=delbeg(a[4]);g++;}
for(int x5=0;x5<r6;x5++)
{b[g]=delbeg(a[5]);g++;}
for(int x6=0;x6<r7;x6++)
{b[g]=delbeg(a[6]);g++;}
for(int x7=0;x7<r8;x7++)
{b[g]=delbeg(a[7]);g++;}
for(int x8=0;x8<r9;x8++)
{b[g]=delbeg(a[8]);g++;}
for(int x9=0;x9<r10;x9++)
{b[g]=delbeg(a[9]);g++;}
for(int i=0;i<n1;i++)
{cout<<b[i]<<" ";}
cout<<endl;
g=0;r1=0;r2=0;r3=0;r4=0;r5=0;r6=0;r7=0;r8=0;r9=0;r10=0;
count++;m2++;}cout<<"enter";cin>>h;
getchar();
}
Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.