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 fbd13c1 commit 7ee9b04Copy full SHA for 7ee9b04
Sorting/insertion_sort.cpp
@@ -0,0 +1,29 @@
1
+# include <iostream>
2
+using namespace std;
3
+
4
+int main(){
5
+ cout<<"Enter the length of array"<<endl;
6
+ int n;
7
+ cin>>n;
8
+ int arr[n];
9
+ cout<<"Enter the elements of array"<<endl;
10
+ for(int i =0; i<n; i++){
11
+ cin>>arr[i];
12
+ }
13
14
+ for(int i=1; i<n;i++){
15
+ int key = arr[i];
16
+ int j = i-1;
17
+ while (key<arr[j] && j>=0)
18
+ {
19
+ arr[j+1]=arr[j];
20
+ j--;
21
22
+ arr[j+1]=key;
23
24
+ for (int i = 0; i < n; i++)
25
26
+ cout<<arr[i]<<" ";
27
28
29
+}
0 commit comments