Professional Documents
Culture Documents
Dsa Assig No1
Dsa Assig No1
Branch:-IT
Roll no:-SI16
Batch:-A
Assignment no:-1 */
#include <iostream>
#include<string.h>
using namespace std;
struct student
{
int Rollno;
char Name[10];
float SGPA;
};
void getdata(struct student S[10],int n)
{
for(int i=0;i<n;i++)
{
cout<<"\nEnter Rollno,Name,SGPA of student:"<<i<<"\t";
cin>>S[i].Rollno>>S[i].Name>>S[i].SGPA;
}
}
void putdata(struct student S[10],int n)
{
cout<<"\n Rollno\tName\tSGPA";
for(int i=0;i<n;i++)
cout<<"\n"<<S[i].Rollno<<"\t"<<S[i].Name<<"\t"<<S[i].SGPA;
}
void bubble(struct student a[10],int n)
{
for(int i=0;i<n-1 ;i++)
{
for(int j=0;j<n-i-1;j++)
{ if(a[j].Rollno>a[j+1].Rollno)
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
{
struct student x;
int j;
x=a[i];
for( j=i-1;j>=0;j--)
{
if(strcmp(x.Name,a[j].Name)<0)
a[j+1]=a[j];
else break;
}
a[j+1]=x;
}
{ s[Pos_pivot]=s[right]; s[right]=pivot; }
return right;
}
void quicksort(struct student s[20], int left, int right)
{
int pivot=partition(s,left,right);
}
int linearSearch(struct student values[20], int n,int Key)
{ int flag=0;
cout<<"\nRollno\tName\tSGPA";
for(int i = 0; i < n; i++)
{
if (values[i].SGPA == Key )
{
flag=1;
cout<<"\n"<<values[i]. Rollno<<"\t";
cout<<values[i].Name<<"\t"<<values[i].SGPA;
}
}
return flag;
}
int BinarySearchN(struct student S[20], int N,char value[20])
{
case 2:
cout<<"\n\nList of records alphabetically";
insertion(S,n);
putdata(S,n);
cout<<"\n\n";
break;
case 3:
cout<<"\nList of students according to first ten toppers from a class";
quicksort(S,0,n-1);
putdata(S,n);
cout<<"\n\n";
break;
case 4:
float find;
cout<<"\nEnter SGPA of a student to find record: ";
cin>>find;
int flag;
flag=linearSearch(S,n,find);
if(flag==0) cout<<"\n Record Not present";
cout<<"\n\n";
putdata(S,n);
break;
case 5:
char Name[20];
insertion(S,n);
cout<<"Enter the Name : ";
cin>>Name;
int pos;
pos=BinarySearchN(S,n,Name);
if (pos==-1)
cout<<"\n\nRollno\tName\tSGPA";
for(i = pos; i>=0; i--)
if(strcmp(S[i].Name,Name)!=0)
break;
for(j = pos; j<n; j++)
if(strcmp(S[j].Name,Name)!=0)
break;
for(k = i+1; k<j; k++)
cout<<"\n"<<S[k].Rollno<<"\t"<<S[k].Name<<"\t"<<S[k].SGPA<<"\
n";
break;
case 6:
return 1;
}
}while(ch<7);
}