This is 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
Write C++ program to store second year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using
a) Insertion sort b) Shell Sort and display top five scores.
This is 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
Prerequiiste
Theory
This is 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
Imp_Ques
This is C code for 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
code in c
This is C++ code for 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
#include<iostream>
#include<iomanip>
using namespace std;
class student
{
public:
double a[20];
int n;
void get();
void display();
void is();
void shs();
};
void student :: get()
{
int i;
cout<<"Enter the number of students in the class:(greater than 5)"<<endl;
cin>>n;
cout<<"Enter the percentage of each student:"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void student :: display()
{
int i,j;
double temp;
cout<<"\nThe percentage of top 5 student are:"<<endl;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]>a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
//cout<<"\nThe percentage of top 5 student are:"<<endl;
for(i=0;i<5;i++)
{
cout<<setprecision(2)<<fixed<<"\n"<<a[i];
}
}
void student :: is()
{
int i,j;
double element;
for(i=1;i<n;i++)
{
element=a[i];
j=i;
while((a[j-1]>element)&&(j>0))
{
a[j]=a[j-1];
j=j-1;
}
a[j]=element;
}
cout<<"\nSorted list is:";
for(i=0;i<n;i++)
{
cout<<setprecision(2)<<fixed<<"\n"<<a[i];
}
}
void student :: shs()
{
double temp;
int gap,i,swapped;
gap=n/2;
do
{
do
{
swapped=0;
for(i=0;i<n-gap;i++)
if(a[i] > a[i+gap])
{
temp=a[i];
a[i]=a[i+gap];
a[i+gap]=temp;
swapped=1;
}
}while(swapped==1);
}while((gap=gap/2)>=1);
cout<<"\nSorted list is:";
for(i=0;i<n;i++)
{
cout<<setprecision(2)<<fixed<<"\n"<<a[i];
}
}
int main()
{
int ch;
char an;
student s;
s.get();
do
{
cout<<"1:Insertion sort\n2:Shell sorts\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
s.is();
s.display();
break;
case 2:
s.shs();
s.display();
break;
default:
cout<<"\nInvalid choice\nPlease re-enter:";
break;
}
cout<<"\nDo you want to continue?";
cin>>an;
}
while(an=='y'||an=='Y');
return 0;
}
This is python code for 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
code in python
This is Java code for 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
code in java
This is 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
If you have a pre-existing submission for this assignment making a new one will override it.
blog comments powered by Disqus
This is 'Insertion And Shell Sort' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy