-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_List.cpp
42 lines (41 loc) · 1.24 KB
/
test_List.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
#include <cstdint>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <list>
#include <string>
#include <iostream>
#include <vector>
#include "List.hpp"
int main() {
List<int> arr{1, 2, 4, 5, 6};
arr.erase(arr.cbegin(), std::next(arr.cbegin(), 2));
arr.insert(arr.begin(), {40, 41, 42});
for (int i = 0; i < 3; i++) {
arr.push_back(100 + i); // O(1)
}
for (int i = 0; i < 3; i++) {
arr.push_front(200 + i); // O(1)
}
size_t i = 0;
for (auto it = arr.cbegin(); it != arr.cend(); ++it) {
int const &val = *it;
printf("arr[%zd] = %d\n", i, val);
++i;
}
List<int> arr2 = arr;
for (auto it = arr2.crbegin(); it != arr2.crend(); ++it) {
int const &val = *it;
--i;
printf("arr[%zd] = %d\n", i, val);
}
printf("arr.size() = %zd\n", arr.size());
arr2.erase(++arr2.begin(), arr2.end());
std::cout << std::boolalpha << "arr2.size() = " << arr2.size()
<< ", arr2.empty() = " << arr2.empty() << '\n';
arr2.erase(arr2.begin());
std::cout << std::boolalpha << "arr2.size() = " << arr2.size()
<< ", arr2.empty() = " << arr2.empty() << '\n';
List<int> arr3(3);
std::cout << arr3.size() << '\n';
}