I want to order this program by name in descinding order.
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define MAX 10
struct std{
char name[20];
int age,year;
};
class radixsort{
struct std arr[MAX];
int n,i;
public:
int a[];
int b[];
void getdata();
void showdata();
void sortLogic();
};
void radixsort :: getdata(){
cout<<"How many elements you require : ";
cin>>n;
for(int i=0;i<n;i++){
cout<<"enter name: ";
gets(arr[i].name);
cout<<"enter age: ";
cin>>arr[i].age;
cout<<"enter year: ";
cin>>arr[i].year;
cout<<endl;
}
}
void radixsort :: showdata(){
cout<<"\n--Display--\n";
for(int i=0;i<n;i++){
cout<<"name:"<<arr[i].name<<endl;
cout<<"age:"<<arr[i].age<<endl;
cout<<"year:"<<arr[i].year<<endl;
}
}
void radixsort :: sortLogic(){
int m=a[0],exp=1;
for(int i=1;i<n;i++)
{
if(strcmp(arr[i].name,arr[i+1].name)>m)
m= strcmp(arr[i].name,arr[i+1].name);
}
while(m/exp>0){
int bucket[10]={0};
for(i=0;i<n;i++)
bucket[strcmp(arr[i].name,arr[i+1].name)/exp%10]++;
for(i=1;i<10;i++)
bucket[i]+=bucket[i-1];
for(i=n-1;i>=0;i--)
b[--bucket[strcmp(arr[i].name,arr[i+1].name)/exp%10]]=strcmp(arr[i].name,arr[i+1].name);
for(i=0;i<n;i++)
strcmp(arr[i].name,arr[i+1].name) == b[i];
exp*=10;
}
}
void main(){
clrscr();
cout<<"\n*****Radix Sort*****\n";
radixsort obj;
obj.getdata();
obj.sortLogic();
obj.showdata();
getch();
}