-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathpretty_array.cpp
More file actions
38 lines (36 loc) · 1.03 KB
/
pretty_array.cpp
File metadata and controls
38 lines (36 loc) · 1.03 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
#include <stdexcept>
#include <iostream>
void PrintArray(const int* begin, const int* end, int constraint = 0) {
if (begin == end || begin == nullptr || end == nullptr)
{
std::cout << "[]\n";
return;
}
int count = 0;
std::cout << "[";
if(begin < end) {
for(const int* ptr = begin; ptr < end; ++ptr) {
if((count == constraint) && (constraint != 0)) {
count = 0;
std::cout << "...\n ";
}
std::cout << *ptr;
if(ptr != end - 1) { std::cout << ", "; }
++count;
}
std::cout << "]\n";
} else {
++end;
for(const int* ptr = begin; ptr >= end; --ptr) {
if((count == constraint) && (constraint != 0)) {
count = 0;
std::cout << "...\n ";
}
std::cout << *ptr;
if(ptr != end) { std::cout << ", "; }
if(ptr == end) { break; }
++count;
}
std::cout << "]\n";
}
}