-
Notifications
You must be signed in to change notification settings - Fork 7
/
tryThis pg722
61 lines (46 loc) · 1.39 KB
/
tryThis pg722
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
// -----------------------------------------------------------------------------
// https://lptcp.blogspot.com/
//
/*
Chapter 20 - Exercise 1
If you haven't already, do all the 'Try This' exercises in the chapter.
p722 - Write a function void copy(int *f1, int* e1, int* f2) that copies the
elements of an array of ints defined by [f1:e1) into another [f2:f2+(e1-f1)).
Use only the iterator operations mentioned above (not subscripting).
*/
// https://github.com/l-paz91/principles-practice/
// -----------------------------------------------------------------------------
//--INCLUDES--//
#include "std_lib_facilities.h"
// -----------------------------------------------------------------------------
void myCopy(int* f1, int* e1, int* f2)
{
int* temp = f1;
while (temp != e1)
{
*f2 = *temp;
++temp;
++f2;
}
}
// -----------------------------------------------------------------------------
int main()
{
const int nSize = 10;
int* n = new int[nSize];
int* temp = n;
for (int i = 0; i < nSize; ++i)
{
*temp = i;
++temp;
}
int* n2 = new int[nSize];
myCopy(n, n+nSize, n2);
keep_window_open();
delete[] n;
delete[] n2;
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------