0

Anyone suggest me the code,algo Sorting the student data- name, percentage, roll no. By the user's choice sorting method

As bubble sort , insertion sort , selection sort ,radix sort , quick sort

13th Sep 2020, 5:45 AM
Yogita Dose
Yogita Dose - avatar
2 Respostas
+ 3
first rule of Discussion box show your attempt. #include<stdio.h> struct student { int rollno; char name[20]; char college[40]; int score; }; int main() { struct student s[20],temp; int i,j,n; printf("\nEnter no. of Students : "); scanf("%d",&n); printf("\nEnter the rollno,name,college name,score "); for(i=0;i<n;i++) scanf("%d%s%s%d",&s[i].rollno,s[i].name,s[i].college,&s[i].score); for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;j++) { if(s[j].score<s[j+1].score) { temp=s[j]; s[j]=s[j+1]; s[j+1]=temp; } } } printf("\nThe Merit List is :\n"); for(j=0;j<n;j++) printf("%d\t%s\t%s\t%d\n",s[j].rollno,s[j].name,s[j].college,s[j].score); return 0; }
13th Sep 2020, 6:05 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
I assume you know the sorting algorithms, you can make the sort functions (bubble and its friends), and use pointer to a function, stores it in an array so when you choose the sorting method, it will directly calls the function. The hard thing is, to use it, the functions must have the same number of parameters. Optionally, use if-else or switch-case.
15th Sep 2020, 11:46 PM
LastSecond959
LastSecond959 - avatar