Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void InsertionSort(int a[],int n)
- {
- int temp;
- for (int i=1;i<n;i++)
- {
- if (a[i]<a[i-1])
- for (int j=i;j-1>=0 && a[j]<a[j-1];j--)
- {
- temp=a[j];
- a[j]=a[j-1];
- a[j-1]=temp;
- }
- }
- }
- int main()
- {
- int n;
- cin>>n;
- int * A=new int [n];
- for (int i=0;i<n;i++)
- {
- cin>>A[i];
- }
- InsertionSort(A,n);
- for (int i=0;i<n;i++)
- {
- cout<<A[i]<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement