Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class student
- {
- public:
- int id;
- string name;
- int credit;
- float cgpa;
- void input()
- {
- cin>>id>>name>>credit>>cgpa;
- }
- void output()
- {
- cout<<"\t"<<id;
- cout<<"\t"<<name;
- cout<<"\t"<<credit;
- cout<<"\t"<<cgpa;
- cout<<endl;
- }
- };
- void CountingSort(student u[200],int n,int loc)
- {
- int i,j;
- int w[10]= {0};
- student v[200];
- for(i=0; i<n; i++)
- {
- w[(u[i].id/loc)%10] =w[(u[i].id/loc)%10]+1;
- }
- for(i=1; i<=10; i++)
- {
- w[i]=w[i]+w[i-1];
- }
- for(j=n-1; j>=0; j--)
- {
- v[w[(u[j].id/loc)%10]-1]=u[j];
- w[(u[j].id/loc)%10]--;
- }
- for(j=0; j<n; j++)
- {
- u[j]=v[j];
- }
- }
- void RadixSort(student s[200],int n)
- {
- int i,j,max=0,loc;
- for(i=0; i<n; i++)
- {
- if(s[i].id>max)
- {
- max=s[i].id;
- }
- }
- for(loc=1; max/loc>0; loc=loc*10)
- {
- CountingSort(s,n,loc);
- }
- }
- int main()
- {
- student s[200];
- int i,j,n;
- cout<<"\nEnter the number of students:";
- cin>>n;
- cout<<"\nEnter Student information: \n";
- for(i=0; i<n; i++)
- {
- s[i].input();
- }
- cout<<endl;
- RadixSort(s,n);
- cout<<"\tID";
- cout<<"\tName";
- cout<<"\tCredit";
- cout<<"\tCGPA";
- cout<<endl;
- for(i=0; i<n; i++)
- {
- s[i].output();
- }
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement