aboutsummaryrefslogtreecommitdiff
path: root/list.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-22 06:09:34 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-22 06:09:34 +0000
commitc0ccb7b38426c3f21fb1b7fe9db19ed6d4613681 (patch)
treed4393287b21331ff8704de410ee1333b379bb451 /list.cpp
parentab5d1c699755f51192d5cab00bf0e601032018b3 (diff)
downloadalgorithms-c0ccb7b38426c3f21fb1b7fe9db19ed6d4613681.tar.gz
algorithms-c0ccb7b38426c3f21fb1b7fe9db19ed6d4613681.tar.bz2
algorithms-c0ccb7b38426c3f21fb1b7fe9db19ed6d4613681.zip
(list)+some flavour text for list program output
Diffstat (limited to 'list.cpp')
-rw-r--r--list.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/list.cpp b/list.cpp
index caa4fbc..f5077f0 100644
--- a/list.cpp
+++ b/list.cpp
@@ -96,15 +96,28 @@ std::ostream& operator<<(std::ostream& ostream, const List<T> *lst)
int main(void)
{
+ puts("Create linked list with 1..10");
auto lst = append<int>(nullptr, 1);
- for (int i = 2; i < 10; ++i)
+ for (int i = 2; i <= 10; ++i)
lst = append(lst, i);
+ printf("Current output for list: ");
std::cout << lst << std::endl;
lst = reverse(lst);
+ printf("Reverse list: ");
std::cout << lst << std::endl;
+ puts("Reverse list again...");
+ printf("Map list with f(x) = 2x: ");
map<int, int>(lst = reverse(lst), [](int x){ return x * 2; });
std::cout << lst << std::endl;
- std::cout << reduce<int>(lst, [](int a, int b) { return a + b; }, 0) << std::endl;
+ puts("Reverse map...");
+ map<int, int>(lst, [](int x){ return x / 2; });
+ printf("Sum all numbers in list: ");
+ std::cout << reduce<int>(lst, [](int a, int b) { return a + b; }, 0)
+ << std::endl;
+ printf("Print all even numbers 1..10: ");
+ auto evens = filter<int>(lst, [](int a) { return a % 2 == 0; });
+ std::cout << evens << std::endl;
delete lst;
+ delete evens;
return 0;
}