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 a8a6550 commit f18d66eCopy full SHA for f18d66e
Sorting/Insertion Sort/C++/Insertion_sort.cpp
@@ -0,0 +1,33 @@
1
+#include<iostream>
2
+using namespace std;
3
+
4
+void insertion_sort(int vet[],int n){
5
+ int i, j, v;
6
+ for(i=0;i<n;i++){
7
+ v = vet[i];
8
+ j = i-1;
9
+ while(j>=0 && vet[j]>v){
10
+ vet[j+1] = vet[j];
11
+ j = j-1;
12
+ }
13
+ vet[j+1] = v;
14
15
+}
16
+int main() {
17
+ ios::sync_with_stdio(0);
18
+ cin.tie(0);
19
20
+ int vet[100000], vetn=0;
21
+ cin >> vetn;
22
+ int i;
23
+ for(i=0;i<vetn;i++){
24
+ cin >> vet[i];
25
26
27
+ insertion_sort(vet, vetn);
28
29
30
+ cout << vet[i] << " ";
31
32
+ return 0;
33
0 commit comments