-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathpretty_array.cpp
More file actions
50 lines (41 loc) · 1.06 KB
/
pretty_array.cpp
File metadata and controls
50 lines (41 loc) · 1.06 KB
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
#include <stdexcept>
#include <iostream>
void PrintArray(const int* begin, const int* end, size_t ogr = 0) {
/*if (begin == nullptr or end == nullptr){
return;
}*/
size_t i_ogr = 1;
std::cout <<"[";
if (end >= begin){
int* p = const_cast<int*>(begin);
while (p < end){
std::cout << *p;
if (p + 1 != end){
std::cout <<", ";
if (ogr != 0 and i_ogr == ogr){
std::cout << "..." << std::endl << " ";
i_ogr = 0;
}
}
p++;
i_ogr++;
}
}
else{
int* p = const_cast<int*>(end);
p--;
while (p >= begin){
std::cout << *p;
if (p != begin){
std::cout <<", ";
if (ogr != 0 and i_ogr == ogr){
std::cout << "..." << std::endl << " ";
i_ogr = 0;
}
}
p--;
i_ogr++;
}
}
std::cout << "]" << std::endl;
}