-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.cpp
66 lines (56 loc) · 934 Bytes
/
main.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
64
65
66
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <iostream>
using namespace std;
void printArray(int ar_size, int *ar)
{
for (size_t i = 0; i < ar_size; i++)
{
cout << ar[i] << " ";
}
cout << endl;
}
/* Head ends here */
void insertionSort(int ar_size, int *ar)
{
if (ar_size <= 0)
return;
if (ar_size == 1)
{
printArray(ar_size, ar);
return;
}
for (int i = 1; i < ar_size; i++)
{
int j = i;
for (int k = j; k >= 0; k--)
{
if (ar[j] < ar[k])
{
int tmp = ar[j];
ar[j] = ar[k];
ar[k] = tmp;
j = k;
}
}
printArray(ar_size, ar);
}
}
/* Tail starts here */
int main(void)
{
int _ar_size;
cin >> _ar_size;
//scanf("%d", &_ar_size);
int _ar[_ar_size], _ar_i;
for (_ar_i = 0; _ar_i < _ar_size; _ar_i++) {
cin >> _ar[_ar_i];
//scanf("%d", &_ar[_ar_i]);
}
insertionSort(_ar_size, _ar);
return 0;
}