-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
68 lines (47 loc) · 2.3 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "alligator.h"
#include "keeper.h"
#include <map>
#include <iostream>
int factorial(const int x) {
return x == 0 ? 1 : x * factorial(x - 1);
}
int main()
{
const auto buff_size = 10;
/* ñîçäàíèå ýêçåìïëÿðà std::map<int, int>
* ñîçäàíèå ýêçåìïëÿðà std::map<int, int> ñ íîâûì àëëîêàòîðîì, îãðàíè÷åííûì 10 ýëåìåíòàìè
*/
std::map<int, int> classic_map;
auto alligator_map = std::map<int, int, std::less<>, custom_alligator<std::pair<const int, int>>> {};
/* çàïîëíåíèå 10 ýëåìåíòàìè, ãäå êëþ÷ - ýòî ÷èñëî îò 0 äî 9, à çíà÷åíèå - ôàêòîðèàë êëþ÷à */
for (size_t i = 0; i < buff_size; ++i) {
auto fac_value = factorial(i);
classic_map.emplace(std::make_pair (i, fac_value));
alligator_map.emplace(std::make_pair(i, fac_value));
}
/* âûâîä íà ýêðàí âñåõ çíà÷åíèé (êëþ÷ è çíà÷åíèå ðàçäåëåíû ïðîáåëîì) õðàíÿùèõñÿ â êîíòåéíåðå */
for(const auto& print : classic_map) {
std::cout << print.first << " " << print.second << std::endl;
}
for (const auto& print : alligator_map) {
std::cout << print.first << " " << print.second << std::endl;
}
/* ñîçäàíèå ýêçåìïëÿðà ñâîåãî êîíòåéíåðà äëÿ õðàíåíèÿ çíà÷åíèé òèïà int
* ñîçäàíèå ýêçåìïëÿðà ñâîåãî êîíòåéíåðà äëÿ õðàíåíèÿ çíà÷åíèé òèïà int ñ íîâûì àëëîêàòîðîì, îãðàíè÷åííûì 10 ýëåìåíòàìè
*/
keeper<int> classic_fifo;
keeper<int, custom_alligator<int>> custom_fifo;
/* çàïîëíåíèå 10 ýëåìåíòàìè îò 0 äî 9 */
for (size_t i = 0; i < buff_size; ++i) {
classic_fifo.push(i);
custom_fifo.push(i);
}
/* âûâîä íà ýêðàí âñåõ çíà÷åíèé, õðàíÿùèõñÿ â êîíòåéíåðå */
for (const auto& i : classic_fifo) {
std::cout << i << std::endl;
}
for (const auto& i : custom_fifo) {
std::cout << i << std::endl;
}
return 0;
}