Anda di halaman 1dari 2

#include<iostream>

#include<conio.h>
#include<process.h>
#include<limits.h>
using namespace std;
class book
{
int bookno[50],booktitle[60];
public:
int k; int price[50];
void input()
{
cout<<"Enter bookno,bookname,price";
cin>>bookno[k];
cin>>booktitle[k];
cin>>price[k];
}
void output()
{
cout<<price[k]<<"\n";
}

}s;
void inssort(int n);
int main()
{
int n;
int i;
cout<<"Enter no of elements";
cin>>n;
int ch;
cout<<"Enter choice 1 0r 2:";

cin>>ch;

switch(ch)
{
case 1:
inssort(n);
break;
case 2:
exit(0);
break;
default:
cout<<"invalid choice";
}
getch();
return 0;
}
void inssort(int n)
{
if(n==20)
{

cout<<"overflow";
}
int i,j;
for (i=0;i<n;i++)
{
s.k=i;
s.input();
}
s.price[0]=INT_MIN;
for(i=0;i<n;i++)
{
s.k=i;
j=i-1;
while(s.price[i]<s.price[j]&& j>=0)
{
s.price[j+1]=s.price[j];
j--;
}
s.price[j+1]=s.price[i];
cout<<"Array after pass-"<<i<<"-is";
for(int m=0;m<n;m++)
{
s.k=m;
s.output();
}
cout<<endl;
}
cout<<"\n\n\n";
for(int l=0;l<n;l++)
{
s.k=l;
s.output();
}
getch();
}