Created
January 16, 2017 17:56
-
-
Save sohana08/1cfc24376a7e21c56cac89225ec3c646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void insertionSort(int n, int * arr) | |
{ | |
int temp,i,j,k; | |
for(i=1;i<n;i++) | |
{ | |
j=i; | |
while(j>0 && arr[j]<arr[j-1]) | |
{ | |
temp=arr[j]; | |
arr[j]=arr[j-1]; | |
arr[j-1]=temp; | |
j--; | |
for(k=0;k<n;k++) | |
cout<<arr[k]<<" "; | |
cout<<endl; | |
} | |
} | |
} | |
int main() | |
{ | |
int n; | |
cin>>n; | |
int arr[n]; | |
for(int i=0;i<n;i++) | |
{ | |
cin>>arr[i]; | |
} | |
insertionSort(n,arr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is my code for insertion sort.
sample input:
1 5 3 6 8 4
output:
1 5 3 6 8 4
1 3 5 6 8 4
1 3 4 5 6 8
i am new to programming and in a learning stage. i want to print the above output but its not giving the first line output.
what is missing in my code??