-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertionsort1.cpp
63 lines (52 loc) · 937 Bytes
/
insertionsort1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
void insertionSort(vector <int> ar)
{
int i;
for(i=ar.size()-1; i>0; i--)
if(ar[i] < ar[i-1])
break;
int elem = ar[i];
bool flag = false;
for(i; i>0; i-- )
{
if( elem < ar[i-1] )
ar[i] = ar[i-1];
else
break;
for(int j=0; j<ar.size(); j++)
cout<<ar[j]<<" ";
cout<<endl;
}
ar[i] = elem;
for(int j=0; j<ar.size(); j++)
cout<<ar[j]<<" ";
cout<<endl;
}
int main(void) {
vector <int> _ar;
int _ar_size;
cin >> _ar_size;
for(int _ar_i=0; _ar_i<_ar_size; _ar_i++) {
int _ar_tmp;
cin >> _ar_tmp;
_ar.push_back(_ar_tmp);
}
insertionSort(_ar);
return 0;
}