We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c66256 commit ea99aa7Copy full SHA for ea99aa7
Insertionsort.cpp
@@ -0,0 +1,33 @@
1
+ // code of the insertion sort
2
+#include<bits/stdc++.h>
3
+using namespace std;
4
+ int main()
5
+ {
6
+ int n;
7
+ cout<<"Enter the size of the array you want to sort"<<endl;;
8
+ cin>>n;
9
+ int arr[n];
10
+ cout<<"Enter the elements of the array"<<endl;;
11
+ for(int i=0;i<n;i++)
12
13
+ cin>>arr[i];
14
+ }
15
+ int j,temp=0;
16
+ for(int i=1;i<n;i++)
17
18
+ temp=arr[i];
19
+ j=i-1;
20
+ while(j>=0&&arr[j]>temp)
21
22
+ arr[j+1]=arr[j];
23
+ j--;
24
25
+ arr[j+1]=temp;
26
27
28
29
+ cout<<arr[i]<<" ";
30
31
+
32
+ return 0;
33
0 commit comments