Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- int main()
- {
- int n,i,j,k,ptr,temp,a[10];
- clrscr();
- cout<<"\nEnter the value for n"<<endl;
- cin>>n;
- cout<<"Enter elements:"<<endl;
- for(i=0;i<n;i++)
- cin>>a[i];
- for(k=0;k<n;k++)
- {
- ptr=k-1;
- temp=a[k];
- while(temp<a[ptr]&&ptr>=0)
- {
- a[ptr+1]=a[ptr];
- ptr=ptr-1;
- }
- a[ptr+1]=temp;
- }
- cout<<"\nSorted array:"<<endl;
- for(i=0;i<n;i++)
- cout<<a[i]<<"\t";
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement