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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <dry/PrintDebug.hpp>
#include <dry/Random.hpp>
#include <dry/List.hpp>
namespace dry
{
template<class T>
void print(Ref< List<T> > list) {
print("[");
for (int i = 0; i < list->length(); ++i) {
print("%%", list->at(i));
if (i + 1 < list->length()) print(", ");
}
print("]\n");
}
int main()
{
typedef List<int> IntList;
{
print("Test 1:\n");
Ref<IntList> list = IntList::create();
list << 1 << 2 << 3;
print(list);
}
{
print("Test 2:\n");
Ref<IntList> list = IntList::create();
list << 1 << 2 << 3 << 4 << 5 << 6;
print(list);
for (int i = 0; i < list->length();) {
if (list->at(i) % 2 != 0)
list->pop(i);
else
++i;
}
print(list);
list->clear();
print(list);
list->append(1);
list->append(2);
print(list);
}
{
print("Test 3:\n");
Ref<IntList> list = IntList::create();
list << 1 << 2 << 3;
print(list);
int x, y, z;
list >> x >> y >> z;
print(list);
print("x, y, z = %%, %%, %%\n", x, y, z);
}
{
print("Test 4:\n");
Ref<IntList> list = IntList::create();
Ref<Random> random = Random::open();
for (int i = 0; i < 10; ++i)
list << random->get(0, 99);
print(list);
print(list->sort());
print(list->unique());
}
{
print("Test 5:\n");
Ref<IntList> a = IntList::create();
a << 1 << 2 << 3 << 4 << 5;
print(a);
print(IntList::clone(a));
}
{
print("Test 6:\n");
Ref<IntList> a = IntList::create(11);
print(a);
}
return 0;
}
} // namespace dry
int main()
{
return dry::main();
}
|