Dsa 1
Dsa 1
NAME: karan
agrawal ROLLNO:
01 CLASS: SE IT
PROGRAM:
#include<iostrea
m>
#include<string.h
> using
namespace std;
struct student
{
int rno;
char
name[20];
float spga;
}list;
int main()
{
student list[15];
int choice, n, key,
result; char x[20];
do
{
cout<<"\n 1) Create Student
Database "; cout<<"\n 2) Display
Student Records ";
cout<<"\n 3) Arrange list of students according to roll numbers in ascending order
(Bubble Sort) ";
cout<<"\n 4) Arrange list of students alphabetically
(Insertion Sort) "; cout<<"\n 5) Find out first ten toppers
from a class (Quick Sort) ";
cout<<"\n 6) Search students according to SGPA(Linear search) ";
cout<<"\n 7) Search a particular student according to name (Binary
search) "; cout<<"\n 8) Exit ";
cout<<"\n Enetr Your
Choice:="; cin>>choice;
switch (choice)
{
case 1:
cout << "\n Enter no. of Student details to be added (max 15) : ";
cin >> n;
accept(list,
n);
break;
case 2:
display(list, n);
break;
case 3:
bubblesort(list,
n); display(list,
n); break;
case 4:
insertionsort(list,
n); display(list,
n); break;
case 5:
quicksort(list, 0, n-1);
cout<<"\n"<< "\t"<< "Roll No"<< "\t"<<" Name" <<"\
t"<< "Marks"; for(int i=n-1; i>=0; i--)
{
cout<<"\n";
cout<<"\t "<< list[i].rno<<"\t "<<list[i].name<<"\t "<<list[i].spga;
}
break;
case 6:
cout<<"\n Enter the marks which u want to
search:="; cin>>key;
search(list, n,
key); break;
case 7:
cout<<"\n Enter the name of student which u want to
search:="; cin>>x;
insertionsort(list,n);
result=binarysearch(list,x,0,
(n-1)); if(result==-1)
{
cout<<" \n Student name you want to search for is not present ! \n";
}
else
{
cout<<" \n The student is present :\t" << list[result].name;
}
break;
case 8:
default:cout<<"\n Invalid choice !! Please enter your choice
again."<<endl; break;
}
}while(choice!
=8); return 0;
}
{
cout << "\n# Details of Student no. " << i +
1 << " - "; cout<<"\n Enter the Roll
number:=";
cin>>list[i].rno;
cout<<"\n Enter the
Name:=";
cin>>list[i].name;
cout<<"\n Enter the
SPGA:=";
cin>>list[i].spga;
}
}
{
if(list[j].rno>list[j+1].rno)
{
temp=list[j]
;
list[j]=list[j
+1];
list[j+1]=te
mp;
}
}
}
do
{
do
i+
+;
while(list[i].spga<v.spga &&
i<=u); do
j--;
while(v.spga<list[j].spg
a); if(i<j)
{
temp=list
[i];
list[i]=list
[j];
list[j]=te
mp;
}
}while(i<j);
list[l]=list[j]
; list[j]=v;
return j;
}
// linear search for marks if more than one student having same marks print
all of them void search(student list[15], int n, float key)
{
int t=0;
cout<<"\n"<< "\t"<< "Roll No"<< "\t"<<" Name" <<"\
t"<< "SPGA"; for(int i=0; i<n; i++)
{
if(key==list[i].spga)
{
cout<<"\n\t "<< list[i].rno<<"\t "<<list[i].name<<"\t
"<<list[i].spga; t++;
continue;
}
}
if (t == 0)
{
cout<<" \n Student SGPA you want to search for is not present ! \n";
}
}
return -1;
}
OUTPUT: