Students list and sort them in C++
C++ Program to make a students list and sort them according to there names, Sort using Merge Sort.
/************************************************************** Author: Arun Vishnu M V Web: www.arunmvishnu.com Description: C++ Program to make a students list and sort them according to there names, Sort using Merge Sort.. ***************************************************************/ #include<conio.h> #include<iostream.h> #include<string.h> struct student { char name[20]; int sem; int regno; float mark; }; struct student students[75]; void msort(int low,int high) // Recursive unction megrge sort { int i,j,h,mid,k; struct student temp[75]; if(lowmid) { while(j<=high) { temp[i]=students[j]; j=j+1; i=i+1; } } else if(j>high) { while(h<=mid) { temp[i]=students[h]; h=h+1; i=i+1; } } for(k=i;k<=mid;k=k+1,h=h+1) temp[h]=students[k]; for(k=j;k<=mid;k=k+1,h=h+1) temp[h]=students[k]; for(k=0;k<=high;k=k+1) students[k]=temp[k]; } } // Main Function int main() { int i,n; clrscr(); cout<<"Enter the no of students: "; cin>>n; for(i=0;i >students[i].name; cout<<"Semester: "; cin>>students[i].sem; cout<<"Register number: "; cin>>students[i].regno; cout<<"Total Marks: "; cin>>students[i].mark; } msort(0,n-1); // Calling the merge sort function cout<<"\n\nThe sorted list is\n\n"; cout<<"Name Semester Regster NO: Total Marks"; cout<<"\n------------------------------------------"; for(i=0;i
Recent Comments