forked from piyush01123/Daily-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sol.cpp
51 lines (42 loc) · 882 Bytes
/
sol.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
#include <vector>
#include <iostream>
class array2D{
private:
std::vector<int> memory;
int ctr;
public:
array2D(std::vector<std::vector<int>>);
int next(void);
bool has_next(void);
void printCTR();
};
array2D::array2D(std::vector<std::vector<int>> v){
ctr = 0;
for (auto vec: v){
for (int i: vec) memory.push_back(i);
}
}
int array2D::next(void){
if (ctr < memory.size()){
return memory[ctr++];
}
return -1;
}
bool array2D::has_next(void){
return ctr < memory.size();
}
void array2D::printCTR(){std::cout<<"ctr value = "<<ctr<<'\n';
std::cout<<"memrotry size = "<<memory.size()<<'\n';}
void test(){
array2D A = array2D({{1, 2}, {3}, {}, {4, 5, 6}});
// std::cout<<std::boolalpha<<A.has_next()<<'\n';
// A.printCTR();
while (A.has_next()){
std::cout<<A.next()<<' ';
}
std::cout<<'\n';
}
int main(){
test();
return 0;
}