-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestFriend.cpp
More file actions
71 lines (57 loc) · 1021 Bytes
/
Copy pathNestFriend.cpp
File metadata and controls
71 lines (57 loc) · 1021 Bytes
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
67
68
69
#include <iostream>
#include <cstring>
const int sz = 50;
struct Holder {
private:
int a[sz];
public:
void initialize ( );
struct Pointer;
friend Pointer;
struct Pointer {
private:
Holder* h;
int* p;
public:
void initialize ( Holder* h );
void next ( );
void previous ( );
void top ( );
void end ( );
int read ( );
void set ( int i );
};
};
void Holder::initialize () {
memset(a, 0, sz * sizeof(int));
}
void Holder::Pointer::initialize (Holder* rv) {
h = rv;
p = rv->a;
}
void Holder::Pointer::next () {
if (p < &(h->a[sz - 1])) p++;
}
void Holder::Pointer::previous () {
if (p > &(h->a[0])) p--;
}
void Holder::Pointer::top () {
p = &(h->a[0]);
}
void Holder::Pointer::end () {
p = &(h->a[sz - 1]);
}
int Holder::Pointer::read () {
return *p;
}
void Holder::Pointer::set (int i) {
*p = i;
}
int main (int agrc, char** argv) {
Holder h;
Holder::Pointer hp, hp2;
int i;
h.initialize();
hp.initialize(&h);
for (int i = 0; i < sz; i++)
}