Skip to content

Commit f18d66e

Browse files
authored
Create Insertion_sort.cpp
1 parent a8a6550 commit f18d66e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for(i=0;i<vetn;i++){
30+
cout << vet[i] << " ";
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)