Sie sind auf Seite 1von 1

#include<iostream.h> #include<conio.h> #include<limits.

h> int arr[15],count=0; void insertion(int n) { arr[0]=INT_MIN; int temp,j; for(int i=1;i<=n;++i) { temp=arr[i]; j=i-1; while(arr[j]>temp) { arr[j+1]=arr[j]; --j; count++; } arr[j+1]=temp; } } void main() { clrscr(); int n; cout<<"\n Enter the limit of array : "; cin>>n; cout<<"\n Enter the elements : \n"; for(int i=1;i<=n;++i) cin>>arr[i]; cout<<"\n\n The given array is : \n\n"; for(i=1;i<=n;++i) cout<<" "<<arr[i]; insertion(n); cout<<"\n The ascending order of given array is : \n\n"; for(i=1;i<=n;++i) cout<<" "<<arr[i]; cout<<"\n\n The complexity of above sorting is : "<<count; getch(); }

Das könnte Ihnen auch gefallen