Created
November 26, 2017 03:22
-
-
Save rahulmalhotra/feb4370854951e70e38e770bbd2694d3 to your computer and use it in GitHub Desktop.
Insertion Sort code compatible with Codeblocks IDE
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; | |
int main() | |
{ | |
int size,arr[50],j=0,store; | |
cout<<"\n\nEnter the size of the Array"; | |
cin>>size; | |
cout<<"\n\nEnter the array"; | |
for(int i=1;i<=size;i++) | |
{ | |
cin>>arr[i]; | |
} | |
for(i=1;i<=size;i++) | |
{ | |
store=arr[i]; | |
j=i-1; | |
while(store<arr[j]) | |
{ | |
arr[j+1]=arr[j]; | |
j--; | |
} | |
arr[j+1]=store; | |
} | |
for(i=1;i<=size;i++) | |
cout<<arr[i]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment